This line currently triggers an error because probably there is nothing after the second =.
What value should return from php to tell filterSubject that is empty.
ng-init="filterSubject="
In some cases filterSubject= gets populated with an id from the query string like ?subject=11
but what do I have to pass from php when the query string is not present
Thank you
Since it looks like you're generating the string in PHP, put single quotes around the filter subject:
ng-init="filterSubject='$subject'"
you can use ternary operator something like this
ng-init="filterSubject = YOUR_EXPRESSION || ''"
You can do something like this :-
<div <?php if($_GET['subject']){ ?>ng-init="filterSubject='<?php echo $_GET['subject']; ?>'" <?php }?>>
.....
</div>
or
<?php
if($_GET['subject']){
$nginit = 'ng-init="filterSubject=\''.$_GET['subject'].'\'"';
}
?>
<div <?php echo $nginit;?>>
.....
</div>
Related
Logic:
if(condition)
Use first `<form ng-submit="action1">`
else
Use second `<form ng-submit="action2">`
Logic in PHP approach:
<?php
if(condition){
echo "<form action='action1.php' >";
}
else{
echo "<form action='action2.php' >";
}
echo "....many many many inputs here...";
echo "</form>";
?>
What I'm trying to write is something like this: (I'm using AngularJs)
<form ng-submit="action1" ng-if="condition1"> ---> First condition
<form ng-submit="action2" ng-if="condition2"> ---> Second condition if first condition fails
....Many many many inputs
</form>
But of course I can simply write something like this: (would be a pain in the ass)
<div ng-if="condition1"> ---> First condition
<form ng-submit="action1" >
....Many many many inputs
</form>
</div>
<div ng-if="condition2"> ---> Second condition if first condition fails
<form ng-submit="action2" >
....Same inputs as in the first div
</form>
</div>
My question is, is it possible to use ng-if (I also tried ng-disabled) inside a <form> tag?
What I'm trying to avoid is to re-code all my inputs inside the form if the only change I will make is the opening <form> tag.
I've searched for an answer and found nothing and the only thing that's left is to confirm and ask.
If the difference is only the function you want to call on submit, you can do the test in the function itself.
<form ng-submit="mySubmit" >
...Many many many inputs
</form>
Controller
$scope.mySubmit = function(){
if($scope.condition1){
// call the function 1
action1();
}else{
// call the function 2
action2();
}
}
Okay after a long try, zcui93 and abimelex codes seems to work without the {} (curly braces):
So the code will be:
ng-submit="condition1 ? action1() : condition2 ? action2() : action3()"
Please confirm if it also works with you. But it really works for me.
hello i have a little bit problem i am working on php4 and apache 1.1
<?php
$something="first second";
echo '<input type="checkbox" name="standard[]" value='.$something.'>first second<br>';
?>
Result:
first
and if
<?php
echo '<input type="checkbox" name="standard[]" value="first second">first second<br>';
?>
Result:
first second
i want my code is like the first one but the result is in second one, how? thanks
do something like that
echo '<input type="checkbox" name="standard[]" value="'.$something.'">'.$something.'<br>';
one way to debugg such things is to check what is their output like view on source or inspect elements
What is the difference between single-quoted and double-quoted strings in PHP? about ' and "
I need to make a DOM substitution, something like this:
$("#target").html('<?php echo $html?>');
where the $html variable could be a complex markup
$html = '<div>
<input type="text" name="test" />
</div>';
Of course I need some kind of escaping, or the javascript engine will break for a syntax problem at the first crlf or quote. In rails there's a simple function escape_javascript that makes it very easy. Is there anything similar in cakephp?
I think using
$("#target").html('<?php echo $this->element("element_path"); ?>');
makes more sense. But it depends on what is in your element_path.ctp file.
On the other hand, it's a bit weird to put replacement HTML in like this. Espacially if it's a lott, I would make an ajax call to load the HTML and have a Controller function return the contents of the element.
$("#target").html('Loading...').load('/myController/loadHtml/');
and the myController
function loadHtml(){
$this->layout = false;
}
and the view for the function app/View/my/load_html.ctp:
<?php echo $this->element("element_path"); ?>
you can do this by using requestAction
in your view file add the below code
$html = $this->requestAction('/tests/func_name');
echo $this->Html->scriptBlock('
$("#target").html('. $this->Js->value($html) .');
');
And in your TestsController.
public function func_name() {
$this->layout = 'layout_name'; // The layout you want here for design.
$this->render('/Elements/element_name'); // you can directly render the content of element by writing like this.
}
I'm trying to over-ride the default layout template of Categories list within the Module
mod_articles_categories
The reason for that is to be able to display the images associated with each category which is set in the params of each category.
The code that I found to show those images is
json_decode($item->params)->image
But it's not working, any ideas?
The "official" way would be to use something like this within the foreach ($list as $item) :
<?php
$params = new JRegistry();
$params->loadString($item->params);
$image = $params->get('image');
if ($image) : ?>
<img src="<?php echo $image; ?>" />
<?php endif; ?>
But you code should work as well. At least it does when I tested it locally. The code I posted would allow you to set a default value for the param. Like $params->get('image', 'foo/bar.png');. Other than that it does about the same.
I'm trying to hide a field and the field label if the value of the field is '0' using the field--field_start_time.tpl.php override method. My template file logic is as follows.
<?php if ($element['#object']->field_start_time != '0')): ?>
<div class="field-label"<?php print $title_attributes; ?>><?php print $label ?>:
</div>
<div class="field-item <?php print $delta % 2 ? 'odd' : 'even'; ?>"<?php print
$item_attributes[$delta]; ?>><?php print render($item); ?></div>
<?php endif; ?>
This is causing chaos with my node render and is obviously wrong. Any help would be GREATLY appreciated. Thanks.
After starting out with Drupal 4 I continued because the community support was awesome.. However after waiting over a day for no answer on drupal.org nor here on what is really a simple question with really awful documentation, I guess I can conclude those days are over.
following code in node.tpl.php
if ($content['field_start_time']['#items']['0']['value'] == '0') {
hide($content['field_start_time']);
}