{foreach from=$s_order_items item="order_item" name="foo"}
What does it do? I want to know so I can tweak.
From the docs:
{foreach} is used to loop over an associative array as well a numerically-indexed array. ... Every {foreach} tag must be paired with a closing {/foreach} tag. ... Required attributes are from and item. ... The name attribute is only required when you want to access a {foreach} property
http://www.smarty.net/docsv2/en/language.function.foreach"">
Related
I'm programatically building a form using Blade components and I can't find how to add attributes dynamically.
For example, I have an $attribute variable that contains ['data-id' => 123, 'step' => 0.01]. I want to integrate it to my form-number component so that the final result is equivalent to:
<x-form-number data-id="123" step="0.01" />.
Thank you.
<x-form-number :data-id="$attribute['data-id']" :step="$attribute['step']" />
from the doc
https://laravel.com/docs/8.x/blade#passing-data-to-components
The keys in the array are dynamic. I don’t know them in advance
Sure you know them in advance they are defined in your class. So you just have to popultae your array with all the keys (with defaut value accepted by your class)
I have an model value, when i do the each iteration it works fine.
<ul>
<li>See here : </li>
{{#each selectedCreditCard.balances.tenures as |balance|}}
<li>Balances is : {{balance}}</li>
{{/each}}
</ul>
But I require to sorted the value by desc way. so I use the computed method to do the desc the array.
sortTenuresBy:['desc'],
sortedTenures: Ember.computed.sort('selectedCreditCard.balances.tenures', 'sortTenuresBy'),
maxTenure:Ember.computed(function(){
return this.get('sortedTenures').get('firstObject');
But getting error as like this:
Assertion Failed: When using #each to observe the array 3,8,12,24, the array must return an object
how to fix this? please help me
If you look at API definition for Ember.computed.sort; it requires a property key (that is selectedCreditCard.balances.tenures in your case) and a sort definition (that is sortTenuresBy in your case). However, if you look at the examples provided; the sort definition must be either a plain property name or a property name followed by sort type such as name:desc or key:asc and so on. In summary; it is not possible to use Ember.computed.sort for plain arrays as in your case. I admit the API documentation is vague.
For your case; you have to either write the computed property as a function; which is what you do not want I suppose; because it is the common way; or you can make use of the following addon. What is great about ember-awesome-macros is you can nest the provided computed macros.
If you look at API for array.sort; it says "combines the functionality of both Array.prototype.sort() and Ember.computed.sort". Hence we can use this one. You want the array to be sorted in descending; I suppose something like the following
sortTenuresBy: array.reverse(array.sort('selectedCreditCard.balances.tenures'))
should work.
I have an attribute if type select. When i try to get value from this attribute content it gives the identification number instead of the value. I call like
$node.data_map.my_attribute_identifier.content
This is expected behaviour. https://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Datatypes/Selection
Raw output
The ".content" of an ezcontentobjectattribute object using this datatype returns an array of the identification numbers (as strings) of the selected options.
I want the value not the identification number. I can get that using attribute_view_gui like
attribute_view_gui attribute=$node.data_map.my_attribute_identifier
But i can't assign value to a variable this way. How can i assign value from a select attribute?
First of all i recommend you to always check default templates in your ezpublish to figure out how should template look...
Maybe this example will help:
<input
id="whatever_id_you_like"
type="text" size="50"
name="ContentObjectAttribute_ezstring_data_text_{$node.object.data_map.YOUR_ATTRIBUTE_SHORT_NAME.id}"
value="{$YOUR_VAR}"
/>
or u can use default view for attribute like this:
{attribute_view_gui attribute=$node.data_map.YOUR_ATTRIBUTE_SHORT_NAME}
also might be helpful - way to find correct path (sometimes you need add ".data_int" or ".data_text" on the end of the path to display data):
{$path|attribute(show,depth)} example:
{$node|attribute(show,2)}
or
{$YOUR_FANCY_VAR.content|attribute(show,2)}
You may want to take a look at the view template of ezselection:
ezselection.tpl
This is the code that eZ Publish uses to view the data type.
content of ezselection.tpl:
{let selected_id_array=$attribute.content}
{section var=Options loop=$attribute.class_content.options}
{section-exclude match=$selected_id_array|contains( $Options.item.id )|not}
{$Options.item.name|wash( xhtml )}{delimiter}<br/>{/delimiter}{/section}
{/let}
I created (in admin) a selection field called color. Now I can't access it. When I run {$note.data_map.color.content|attribute(show)} it prints value. But I can't access it without attribute(show). What can I do?
eZSelection's content is an array, access the 0 key on content to get the value.
{$node.data_map.email_option.content.0}
don't forget you always have attribute_view_gui* which can help you quite a lot in these cases.
you can set the attribute to be information collector and collect that information from user.
*{attribute_view_gui attribute=$node.data_map.color}
You need to match the option array defined in your class attribute with the id of the selected option in order to get the value of it.
$node.data_map.color.class_content.options will contain all the options available (associative array with id and name values)
$node.data_map.color.content is an array containing the ids of the selected options (because this field can handle multiple selection).
Even if the {section} function is deprecated I'll suggested that you have a look at the default template rendering an ezselection attribute : design/standard/templates/content/datatype/view/ezselection.tpl
If you have "Multiple choice" type than you can do it like this:
{if $node.data_map.color.has_content}
{foreach $node.data_map.color.content as $colorID}
{foreach $node.data_map.color.class_content.options as $opt}
{cond($opt.id|eq($colorID), $opt.name, '')}
{/foreach}
{/foreach}
{/if}
I have a dynamically generated Smarty variable in PHP. I want to access it with name ,
Say for example there is a smarty variable {$asdf} which was generated dynamically and i have an array that has 'asdf' i want to use this array and access {$asdf}.
{$asdf} prints a input element [rendered] ;
$array = array('asdf');
{foreach from=$array item=x}
{$x}
{/foreach}
//but {$x} is not giving renderend input instead it is giving $asdf
where am i going wrong?
It is generally atypical to do this type of work in a template file. You should separate your template and logic as much as possible -- there's no plausible scenario in which you could not simply prepare the needed variables for your template in php and pass them on to the template in a useable structure.
That said, it is possible. Within a template, all variables that were passed to the template are accessible in an array, Smarty::_tpl_vars. Within a template, one may interact with this array using the {php}{/php} tags, where it can be referenced via $this --
{php}
$unknownValue = $this->_tpl_vars[
$this->_tpl_vars['known_key']
];
// for example...
$this->_tpl_vars['magicalValue'] = $unknownValue;
{/php}
Magic: {$magicalValue}
I cannot reiterate enough, however, that it is generally bad practice to place such logic inside a template.