I'm trying this method to add static includes to my namespaces but I'm facing the problem that, static includes from nested namespaces are not included in the base template. To make the problem more concrete, below I post some example code:
base.mako
<!DOCTYPE html>
<head>
% for ns in context.namespaces.values():
% if hasattr(ns, 'includes'):
${ns.includes()}
% endif
% endfor
</head>
<body>
${next.body()}
</body>
</html>
child.mako
<%inherit file="base.mako"/>
<%namespace name="rb" file="buttons.mako"/>
${rb.render_buttons}
buttons.mako
<%namespace name="lib" file="lib.mako"/>
<%def name="includes()">
<script type="text/javascript" src="${request.static_url('project:static/lib.js')}"></script>
</%def>
<%def name="render_buttons()>
<button onclick="some_function_from_lib_js()">Click me!</button>
${lib.render_text()}
</%def>
lib.mako
<%def name="includes()">
<script type="text/javascript" src="${request.static_url('project:static/other.js')}"></script>
</%def>
<%def name="render_text()">
<button onclick="some_function_from_other_js()">No! Click me!</button>
</%def>
This is just an example but I hope it suffices to describe my problem.
There are syntax errors in the code you posted. Also, there are references to external (request for example) entities. Please always make sure your code is correct and works before posting.
The problem seems to be that context.namespaces is collection of namespaces declared only in templates in inheritance chain. This could be inferred from the following statement from docs:
Iterating the values of this dictionary will provide a Namespace
object for each time the <%namespace> tag was used, anywhere within
the inheritance chain.
Your inheritance chain consists from child.mako and base.mako only. Out of these only child.mako declares namespace (rb) and thus this is the only namespace in context.namespaces. You can see this easily if you insert ${ns.uri} after % for ns in context.namespaces.values(): line. This will render buttons.mako string alone in the output.
The solution in your case would be to look for includes defs not only in namespaces declared in templates in inheritance chain but also in namespaces declared by those namespaces. Something like
% for ns in context.namespaces.values():
% for ns2 in ns.context.namespaces.values():
% if hasattr(ns2, 'includes'):
${ns2.includes()}
% endif
% endfor
% if hasattr(ns, 'includes'):
${ns.includes()}
% endif
% endfor
However it does not work from what I see and don't know why.
Related
I'm using the current release 4.3.3 of Middleman.
I'd like to define a custom helper which accepts a block. For the sake of simplicity, here's a nonsensical example of wrap_me which wraps the block content with the given tag.
It should be possible to implement this with capture_html provided by Padrino (which is explicitly mentioned in the Middleman docs):
module CustomHelpers
def wrap_me(tag, &block)
captured = capture_html(&block)
concat_content "<#{tag}>" + captured + "</#{tag}>"
end
end
Put to use in ERB:
<%= wrap_me('span') do %>
Hello
<% end %>
Now this raises a SyntaxError on line 274 of tilt-2.0.9/lib/tilt/template.rb which tries to eval a string. It appears, the capture is going beyond the "end".
What am I doing wrong here? How to use capture_html and concat_content if Tilt is preventing helpers from having blocks?
Thanks for your help!
(I'll ask the same question in the Middleman forum.)
Apparently, when using blocks, the equal sign has to be dropped. The following works:
<% wrap_me('span') do %>
Hello
<% end %>
I would like to keep my polymer components nicely encapsulated but right now if I try to import any external modules into the components I get an undefined error for 'import'.
I use Webpack to bundle up my app but this packs up my javascript files only.
Is there a way to do keep my Polymer component encapsulated into a single html file or I must separate the js part when it comes to imports?
Example:
<link rel="import" href="../bower_components/polymer/polymer.html">
<dom-module id="my-new-view">
<template>
<style>
</style>
<h1>New view</h1>
</template>
<script>
import { myConstant } from '../module.js'; //<---- this throws error for the import'
Polymer({
is: 'my-new-view'
});
</script>
</dom-module>
Only Webpack
For it to work like that, you'd have to export module.js as a library so it can be used outside of Webpack. Once it's part of a library and included in the global scope you can then access it like
var myConstant = Module.myConstant;
Polymer({
is: 'my-new-view'
});
It's likely much easier to just have your JS code in a separate file.
See https://stackoverflow.com/a/34361312/4722305.
Crisper
One other option might be to run https://github.com/PolymerLabs/crisper over your code before calling into webpack. Crisper will remove the <script> tags from your code and convert them into JS files that will be compatible with Webpack.
I am trying to set up a tree view using an entity framework data object (EF 6 in MVC 5). I've run into a problem when I try to Render() my tree.... I receive the 'Object doesn't support property or method 'igTree'' error.
My code to set up the tree (in my view):
#(Html.Infragistics()
.Tree()
.Bindings(bindings =>
{
bindings.
TextKey("L1Name").
PrimaryKey("L1TODSID").
ValueKey("L1TODSID").
ChildDataProperty("L2Name").
Bindings(b1 =>
{
b1.
TextKey("L2Name").
ValueKey("L2TODSID").
PrimaryKey("L2TODSID");
});
})
.DataSource(Model)
.DataBind()
.Render()
)
I get no errors until I add in the 'Render()' call.
I read a post on the Infragistics forum asking if they will be supporting MVC 5... Are they not doing that? Is that my issue?
Also, these are my calling scripts:
<!-- Ignite UI Required Combined CSS Files -->
<link href="#Url.Content("~/igniteui/css/themes/infragistics/infragistics.theme.css")" rel="stylesheet" />
<link href="#Url.Content("~/igniteui/css/structure/infragistics.css")" rel="stylesheet" />
<script src="#Url.Content("~/Scripts/modernizr-2.7.2.js")"></script>
<script src="#Url.Content("~/Scripts/jquery-2.0.3.min.js")"></script>
<script src="#Url.Content("~/Scripts/jquery-ui-1.10.3.min.js")"></script>
<!-- Ignite UI Required Combined JavaScript Files -->
<script src=#Url.Content("~/igniteui/js/infragistics.core.js")></script>
<script src=#Url.Content("~/igniteui/js/infragistics.lob.js")></script>
#(Html.Infragistics()
.Loader()
.ScriptPath("~/igniteui/js/")
.CssPath("~/igniteui/css/")
.Render()
)
Thanks in advance!
EDIT: Final Resolve.
Just in case anyone else ever runs accross this situation...
I knew this error ('Object doesn't support property or method...') could be caused by jquery loading twice. Thought I had thoroughly checked all script calls. However, being new to .NET and MVC 5 (razor), I completely missed this line at the end of my layout page (I didn't set up the project originally):
#Scripts.Render("~/bundles/jquery")
So...
In the end, I was initiallizing JQuery in my script block at the top (with a call to the minified file), then I was calling it again, which is what caused the error.
A big thanks to #nemesv, because the fact that he explained the loading process in greater detail than I could find online gave me the confidence to know that I was doing things correctly on that side. Then I just needed to hunt down the second call to initialize JQ.
Thanks again!
By default (if you are not using the loader infrastructure)
The .Render() call will render the following HTML:
<script type="text/javascript">
$(function () {$('#Tree1').igTree({ dataSource: ... });});
</script>
So you get the exception on the igTree function call which would initialize the tree.
Your igTree function can be undefined:
If you are not loading the necessary igniteui scripts:
<script src=#Url.Content("~/igniteui/js/infragistics.core.js")></script>
<script src=#Url.Content("~/igniteui/js/infragistics.lob.js")></script>
Make sure that these scripts are included in your view or in your Layour file
If you are not using the rigth path or the scripts file are not there on the server:
Check for broken link in your browsers network console (F12 in IE/Chrome FireBug in FF):
If you 404 error next to your script you will know that they are not loaded correctly and you need to fix the paths.
If you are referencing jQuery more than once can cause this error too:
Foe example you have the <script src="#Url.Content("~/Scripts/jquery-2.0.3.min.js")"></script> in a partial which is loaded by Ajax multiple times, etc.
Make sure that you are referencing all your scripts once.
In the case of using the loader
When using the Loader infrasturure the .Render() call will render the a different HTML:
<script type="text/javascript">
$.ig.loader('igTree', function() {$('#Tree1').igTree({ dataSource: });});
</script>
So the loader will load the necessary script required by the tree so you don't need to include infragistics.core.js and infragistics.lob.js.
When using the loader in theory you could not the get the exception.
But if you call: #(Html.Infragistics().Loader()... after your Html.Infragistics().Tree() then the MVC wrapper does not that you are using the loader so it renders the HTML like when you don't use the loader so if you rightfully not referenced the infragistics.core.js and infragistics.lob.js. then you get the exception even if you are "using" the loader.
So make sure that you call #(Html.Infragistics().Loader()... before using any of the Infragistics controls.
I was also facing the same issue with MVC 4 and Ignite UI. Removing #Scripts.Render("~/bundles/jquery")
from the _Layout.cshtml resolved the issue.
is it possible to add arguments to the sctipt element
e.g.
<script
...
src="XX.js"
></script>
i want to add the argument hello="world" so this is added to the page:
<script
...
src="XX.js"
hallo="welt"
></script>
Reason: I have a js library (aloha-editor) which depends on a parameter for loading it's plugins (and the main functionallity is actuall in a plugin). However I only want to load the plugin when the user want's to edit and requirejs is the best choice since it is used at other parts in the application.
If you are wrapping the aloha script in a define function you could pass arguments like this (link):
//in main appfile
require.config({
'config': {
'aloha': {
src: "XX.js",
hallo: "welt"
}
}
});
//and in the aloha file
define(['module'], function (module) {
var src = module.config().src,
hallo = module.config().hallo;
... // the aloha code
});
There was also an alternative "simplified" syntax in the docs.
Edit: Maybe I misunderstood the question, if you where asking if it's possible to add html attributes to a script tag already on the page: <script src='' data-src='xx.js' data-hallo='welt'></script> is the new html5 syntax for adding custom attributes to tags, everything preceded by data- is correct syntax.
There's an addon that I used on my Sharetronix website (a microblogging platform for those who aren't familiar with it) which is supposed to allow me to add a page to the root folder of my website. But, I get this message when I go to the page that I just added.
Fatal error: Using $this when not in object context in /home/u556426868/public_html/forum.php on line 2
I've done some research online and I know so much as the "$this" object shouldn't land outside of the "newtemplate_code()" but I don't know what I'm supposed to do in terms of replacing and fixing the code so that the page works.
The code for the whole page is as the following:
<?php
$this->load_template('header.php');
?>
<div id="pagebody" style="margin:0px; border-top:1px solid #fff;">
<div><div id="contacts_left" style="width:100%;"> <div class="ttl">
<div class="ttl2"><h3>iState RPG - The Neovita RPG Forum</h3></div></div>
<br><br>
<center><iframe name=”FRAMENAME” src=”http://istate.serverforumhosting.com/portal.php” width=”1000? height=”1100? frameborder=”1? scrolling=”yes” allowautotransparency=true></iframe></center>
<! REMOVE FROM HERE THE DUMMY CONTENT !>
<b>DOWNLOAD</b> this plugin here(2kb).<br><br>
<center>
<a href="http://sharetronix.com/sharetronix/demo/getfile/pid:public_3965797/New%20Page.rar" target="_blank" title="Download">
<img src="http://wb-cc.de/oscommerce/images/download-1.gif" border="0">
</a><br><br>
Brought to you by iState - The state of you!
</center>
<! REMOVE END !>
</div>
</div>
</div>
<?php
$this->load_template('footer.php');
?>
Like I said, I'm new to PHP coding and so I will need some clarification. So by the way, thanks for helping me!
You are using $this outside a class. I suggest you are trying to use a 3rd party library for templates. First of all you have to include the needed files link this:
include("path/to/your/class.php");
Then you have to find out the name of the class, let's say it starts like this:
class Template
Then you will have to initialise it with
$template = new Template();
and call the needed function
$template->load_template('header.php');
More details about path and usage may be in the installation files of the library.
Oh and $this is only for usage inside classes, e. g.:
class foo
{
function bar()
{
// Do something
}
function do_bar()
{
$this->bar();
}
}