I wonder if anyone can help me. I'm using PodHawk - a basic podcast cms, I would like the admin area file select to show my files in order - by name.
The select/option dropdown uses this code, is there a straightforward way to get the dropdown to display in order by name,. I've searched but cant find anything in the Smarty documentation, but I'm probably using the wrong terminology!
{foreach from=$upload item=file}
<option value="{$file|escape:'url'}">{$file}</option>
{/foreach}
many thanks rob
Solved with many thanks to poster below -
{$upload|#sort:$smarty.const.SORT_NUMERIC}
{foreach from=$upload item=file}
<option value="{$file|escape:'url'}">{$file}</option>
{/foreach}
cgwyllie neglected that asort() returns a boolean, not the sorted array. So his approach wouldn't work. As the index is not used, a(ssociative)sort is not required.
{$_foo = $upload|sort:$smarty.const.SORT_LOCALE_STRING}
{foreach $upload as $file}
<option value="{$file|escape:'url'}">{$file|escape:"html"}</option>
{/foreach}
should do the trick. Make sure you really need that $file urlencoded, otherwise change escape:"url" to escape:"html".
(the above is Smarty3 syntax)
If the variable $upload contains an array of file names, then it should be possible to apply the PHP asort function (http://php.net/asort) to the array as a smarty modifier.
{foreach from=$upload|#asort item=file}
<option value="{$file|escape:'url'}">{$file}</option>
{/foreach}
The # symbol is needed to apply the modifier to the array as a whole, and not to each individual element. (See http://www.smarty.net/docsv2/en/language.modifiers.tpl)
If the array is of more complex data structures than just strings, the following discussion may be of use to you: http://www.smarty.net/forums/viewtopic.php?t=1079&postdays=0&postorder=asc&start=0
Edit
As mentioned by rodneyrehm, this solution is not quite correct although the poster found a satisfactory solution at: http://www.smarty.net/forums/viewtopic.php?t=1079&postdays=0&postorder=asc&start=0
Related
I want to be able to get the text of the selected option and not the value. I would use the value but Angular is changing it and putting the value in a ng-reflect-ng-value attribute.
<option _ngcontent-c1="" value="5: 1" ng-reflect-ng-value="1">Miscellaenous</option>
This will work, but I want to check that it equals "Miscellaenous"
cy.get('#id-9999').find('.categoryList').should('have.value','Miscellaenous');
This worked for me:
cy.get('#id-9999').find('.categoryList').find(':selected').contains('Miscellaenous')
This is how it should be done:
cy.get('#id-9999').find('option:selected').should('have.text', 'Miscellaenous');
Among other things, it checks for the exact match and not for a substring (like in your solution).
We've found that chaining find() off get() sometimes breaks our tests, so we use this other way:
cy.get("#my-select-element option:selected")
.should("have.value", 3);
as opposed to:
cy.get("#my-select-element")
.find("selected")
.should("have.value", 3);
When using Cypress I found that :selected did not work, however :checked did work. So to modify one of the other answers here, this works (at least for me):
cy.get("#my-select-element option:checked")
.should("have.value", 3);
Well, i have a question and i am so confused that i decided to ask you.
What do these statements show?
Does this display the value? (the value property of option element OR the text(JHIDE or JSHOW))?
$this->params->get( 'show_title');
And what does this statement with the two parameters indicate?
$this->params->get( 'show_title', 'JHIDE');
Could it be written in another way?
Here is the XML part of this statement:
<field name="show_title" type="list" default="" label="SHOW_ARTICLE_TITLE"
description="SHOW_ARTICLE_TITLE_DESCR">
<option value="0">JHIDE</option>
<option value="1">JSHOW</option>
<option value="">USE_GLOBAL</option>
</field>
I am very confused and i cant find the answer, even though i have printed their values with var_dump, print_r, echo etc.
Thanks in advance!
show_title displays the value from the option that is selected.
'JHIDE' which is the second parameter, defines the default.
The default doesn't technically have to be defined but it's best to do so. It should not always be written any other way as it's a simple method that Joomla coding standards.
I have the following elements defined within a SitePrism page:
element :type, "select[id='type']"
elements :type_options, "select[id='type'] option"
And in my cucumber step definitions I have the following code to select an item from the select box based on the elements value:
#app.new.type_options.each {|name| name.click if name.text.upcase == value.upcase}
I don't really like this implementation but it does work perfectly when running Capybara in chrome but fails when I run it headless so I figure there must be an alternate / better way to select drop down items.
Ideally I'd like to be able to do something like #app.new_r.r_type.select 'value', but I can't work out how to do this in SitePrism.
So, my first question is, can anyone recommend an elegant way to select an item from a drop down based on value from SitePrism?
And my second question is, any idea why the above code fails when running headless?
I had a similar problem, where I couldn't get it to select the option I wanted. I came across this question and it made me realize my problem was that you have to send the text, not the value, to the select().
For example, if I have HTML like
<select id="things">
<option value="thing1">The First Thing</option>
<option value="thing2">The Second Thing</option>
<option value="thing3">The Third Thing</option>
</select>
And in my SitePrism::Page class I have:
element :things, "select[id='things']"
I thought I needed to do:
#my_page.things.select("thing1")
That does not work. Instead you have to do:
#my_page.things.select("The First Thing")
I know this is slightly different than trying to select based on a value you get from SitePrism, like was originally asked. But I thought this distinction about what to pass to select() might help someone.
I want to iterate thru single array and disable caching only for some elements.
So my idea was to keep key and get element by key in nocache section. Unfortunatelly i haven't found any possibility to:
assign cached $rec#key in nocache section,
or keep variable key definition in cached section.
Is there any way (without smarty code modification) to do it ?
here my test.tpl:
{foreach $array as $rec}
{if $rec.dynamic}
{assign var="key" value=$rec#key}
{nocache}
{$array[$key].text}
{/nocache}
{else}
{$rec.text}
{/if}
{/foreach}
and test.php:
<?php
include_once 'libs/Smarty.class.php';
$smarty=new smarty();
$smarty->caching=1;
$smarty->assign('array',array(
'r1'=>array('dynamic'=>true,'text'=>'dynamic'),
'r2'=>array('dynamic'=>false,'text'=>'static')
));
$smarty->display('test.tpl');
(of course i will use it for much more complicated things than text display:) )
I tried lot of tricks and by myself i think it is not possible, please tell me i am wrong :)
Finally, I have found a solution: Use count in your loop.
{nocache}
{counter start=0 skip=1 assign="count"}
{/nocache}
{section name="co" loop=$publication}
{nocache}
{$publication[$count].id}
{counter}
{/nocache}
{/section}
What you are trying to accomplish is, as of Smarty 3.1.x, not possible. With 3.2 Smarty will allow you to "export" values into a {nocache} section to ensure they're available when the template is re-executed.
Until 3.2 is released (don't ask for a date, I don't know) you may be able to do this yourself using a compiler function.
I use the pagination helper from CodeIgniter and it works. But when I see the result in my browser, I can observ unwanted spaces. CodeIgniter seems to insert them in an automatic way.
In my view:
<div><?php echo $this->pagination->create_links(); ?></div>
The code generated behind (html):
<div>
Previous
1
2
<strong>3</strong>
4
5
Next
Last
</div>
So there is a space before my previous link and two spaces before my "Last" link. Same thing happens when it's reversed (two spaces after my "First" link).
Why? It really blow my mind! Please do you know how to remove them?
Any suggestions gratefully received.
Solution (thanks to uzsolt's answer) : It works with first_tag_close and last_tag_open set to '' (see comments for more details).
Maybe you can set num_tag_open and num_tag_close config variable.
After trying all sorts of things by setting the config values from both within my controller and a application/config/pagination.php file. I managed to solve it by going into system/libraries/Pagination.php and reset the default values without any ' '.
Hope this helps someone else.