I'd need some help on (IP 4.0.16).
I'm trying to pass parameters to a js file by the function ipAddJs
ipAddJs('file.js', array('id' => 123))
but in the generated html the result is
<script type="text/javascript" src="[path]/file.js?1" id="123"></script>
am i doing something wrong or is it a bug?
Second parameter in ipAddJs function is for HTML attributes. Therefore, the result is as expected.
If you want to add variable to a filename, just put it as you want them:
ipAddJs('file.js?id=123');
Related
I am trying to change the title of a page.
The default.ctp view has the following code:
<title>
<?php echo $this->fetch('title'); ?>
- Welcome
</title>
I'm trying to use the following code in the controller of the page:
$title = 'Overview';
$this->set('title');
But unfortunately I do not see see 'Overview - Welcome', but only the name of the function of the controller followed by ' - Welcome'.
Can anyone help me to find the problem why it is not working?
Don't know if $this->set('title') will work
I usually use the 'compact' function to set the variables as they're named.
Like this: $this->set(compact('title')); or just simply this $this->set('title', $title);
You can define what $this->fetch('title') returns using View::assign() function that sets block's value this way:
$this->assign('title', $title);
See more in the documentation about view blocks.
I think instead of:
$this->set('title');
you must use:
$this->set('title', $title);
I wan to be able to select the contents of the following script tag.
<script type="text/javascript" class="sample">
/* <![CDATA[ */
var test = {};
test.hey = 1;
/* ]]> */
</script>
Running $(".sample").text() in geb results in an empty string. Is there a way to access the plain text script contents?
Not familiar with the framework you mentioned but it is possible that $(".sample").text() returns an empty string because the code within the <script> tag is not a visible piece of HTML. As mentioned in this SO post try using either $(".sample").html().
This of course is assuming that the gebish framework API supports a .html() method on the object. You could find something equivalent in the API docs if this solution does not work.
Maybe I'm asking my question wrong since it seems like the answer should be relatively easy to search for. I am parsing some .md files in express and returning the response to a jade template.
= body returns <h1>my content</h1> as a string.
#{body} returns <<h1>my content</h1>><!--<h1-->my content> or effectively:
<
my content #as a styled h1
>my content>
Thanks for any help.
UPDATE FOR CLARITY:
My question is - why is the content returning twice.
why is the content returning twice.
Because with the syntax of #{VARIABLE} Jade replace the variable with the value and interpret it as a HTML tag. For example:
passing a local variable {foo: 'bar'} and this template
#{foo}
generat this HTML
<bar></bar>
So you should pass the content and don't let interpret it by jade using = or != for unbuffered code:
!=body
btw: a whitespace is forbidden between = and the variable!
I have a php file under protected/views/directory_controller_name with formatting like that
<p>
<?php echo $model->title;?>
</p>
...
I display the file with classic method in the controller :
$this->render('filename',array('model'=>$model));
But know, I need to send an email with the same template/layout so I want to store the render of the file in an variable like
$msgHTML = $this->renderInternal('_items', array('model'=>$model));
But it doesn't work!
How can I get render view from a file and store in a variable?
Is it possible?
I don't want to use:
$msgHTML = '<p>'.$model->title.'</p>'
...
Because the file is very long and I don't want to duplicate code!!!
Don't use the renderInternal method, use renderPartial instead. Render internal is low level method and should not be used in such context. To catch the output just set the $return parameter to true:
<?php $output = $this->renderPartial('_subView', $dataArray, true); ?>
$msgHTML = $this->renderInternal('_items', array('model'=>$model), true);
http://www.yiiframework.com/doc/api/1.1/CBaseController#renderInternal-detail
I might be missing something, but can't you just use regular render() with the return argument set to true? Then you can just use a view 'name' instead of knowing the path. (And unless my trusty stack trace logger is broken, renderFile and renderInternal take the same fully qualified path argument. At least I can see renderPartial() passing the full path to my view file to renderFile.)
you can do this with these ways
1) if you want to get the output with header and footer (i.e ) full layout then do this
//add true in the last parameter if you want a return of the output
$htmloutput=$this->render('_pdfoutput',array('data'=>'nothing'),true);
2) similarly if you don't want to get the layout files just use renderpartial in the same way
$htmloutput=$this->renderpartial('_pdfoutput',array('data'=>'nothing'),true);
you will get the html of files in the variable . use this anywhere
I'm just getting started with dojo, and I've understood that dojo.query is the same as $ in jQuery.
But I haven't figured out what it returns. Is it a specialized object like in jQuery?
What I'm trying to do (with no luck) is:
dojo.query("output").innerHTML = data;
//this doesn't work either:
dojo.query("output").html(data);
//tried accessing by id as well
dojo.query("#output").html(data);
//and tried to access a div, incase dojo has some issues with html5 elements
dojo.query("#divOutput").html(data);
And I'm currently using the new html5 elements:
<output id="output">Output goes here</output>
<div id="divOutput">non-html5 output goes here</div>
And I can't seem to find a good list on what to do with objects returned by dojo.query()..
edit: Okay, I think dojo is just messing with me now. I found this method: addContent() and that works on the above selector. But I don't want to add content, I want to replace content...
The query method returns a NodeList object.
In the ref for NodeList you can find a list of functions that you can apply to the list
of elements. There is no innerHTML function for the list, but the html function should work.
There is no "output" element in HTML, perhaps you try to target elements with the class name "output"?
dojo.query(".output").html(data)
Or the element with id "output"?
dojo.query("#output").html(data)
If you want to replace all the output tags' content with the same thing, then this code should always work:
// replace the contents of ALL <output> tags
dojo.query('output').forEach(function(node) { node.innerHTML = data; });
Dojo also provides a little shortcut for these kinds of things. You can specify a string to NodeList's forEach function like this:
// replace the contents of ALL <output> tags (as long as data is global)
dojo.query('output').forEach("item.innerHTML = data;");
The word item in the string is special. (This is a pain to debug, so it might not be worth it.)
As was said above, query method returns NodeList object, so you can iterate it's result as array, or use dojo methods that work with NodeList (e.g. attr):
dojo.query("#divOutput").attr("innerHTML", data);
But as soon as you are trying to query nodes by id, it would be better to use dojo.byId() method, which returns domNode:
dojo.byId("divOutput").innerHTML = data;
Or in more dojo style:
dojo.attr(dojo.byId("divOutput"), "innerHTML", data)
Try this by adding the [0] like this:
dojo.query("output")[0].innerHTML = data;
Also, there is a dojox.jq wrapper (in development, coming in 1.4) which emulates the JQuery return object APIs
The documentation seems to be a mess, this is the only thing i get to work with 1.7,
dojo.query("whatever").forEach(function(node, index, array)
{
node...
});