Twig file to Tpl conversion of opencart - twig

{% if languages|length >= 1 %}
this is the twig file code . how can we write this code in tpl file . i am converting opencart 3.0.2.0 theme into opencart 2.3.0.2 .
I am facing problem to solve | this sign . mean how can i convert this line in tpl exactly .thanks

You can use count function:
<?php if(count($languages) >= 1){ ?>
<?php } ?>

Related

Twig equivalent of lcfirst

I'm not able to find a equivalent of lcfirst php function in Twig, my need is to lower only the first letter of a word ?
If such function doesn't exist, what is the best way to do it ?
As discussed in this issue on Github, you could use:
{{ foo[:1]|lower ~ foo[1:] }}
See this working example.
Just add the function into twig by chaining it with a filter, e.g.
$twig->addFilter(new \Twig\TwigFilter('lcfirst', 'lcfirst'));
Then use it inside any twig template like
{{ string | lcfirst }}
You can use a capitalize filter:
{{ 'my first car'|capitalize }}
{# outputs 'My first car' #}
https://twig.symfony.com/doc/1.x/filters/capitalize.html

Ternary operator won't return HTML

I would like to use the ternary operator of Twig but it shows me the HTML tags as text.
{{ (sender.firstName or sender.lastName) ? "<strong>#{sender.firstName} #{sender.lastName}</strong>" : '<strong>Unknown</strong>' }}
The result is <strong>My Name</strong> but it should be My Name.
You have to apply the raw as the output is not marked as safe when concatenating html with twig
{{ (sender.firstName or sender.lastName ? "<strong>#{sender.firstName} #{sender.lastName}</strong>" : "<strong>Unknown</strong>")|raw }}
demo

Kentico text/xml transformation conditional statmement

I have a transformation, used with a repeater, for a slider. All is working well. I have a slide caption, that isn't required. What I'm struggling with is a conditional statement where the caption tag doesn't show.
Here's my transformation:
<section class="imageSlide">
<figure role="group">
<img src="{% SlideImage %}" alt="{% SlideAlt %}">
<figcaption><p>{% SlideCaption %}</p></figcaption>
</figure>
</section>
What I'm hoping to do is not render the figcaption if there is no SlideCaption. SlideCaption isn't a required item. I had though if using jquery to change the display type of the <p></p> tags were empty, but want to avoid a lot of DOM manipulation.
I know that the syntax is something like this, but I haven't found a good example I can use as a base solution.
{% if(....) %}
Something like this should work. Didn't test it, so may need some tweaks.
{% IfEmpty(SlideCaption, "","<figcaption><p>" + SlideCaption + "</p></figcaption> ") %}
Another example for future reference if you dont want to be limited to using IfEmpty
{% if(SlideCaption != "" && SlideCaption != null) { return "<figcaption><p>" + SlideCaption + "</p></figcaption>" } %}

ExpressionEngine - PHP in template, Print something if entry has certain field value?

I have a template that is used for entries. The entries have a field that will always have 1 of 2 values. Can I write some PHP to show something different depending on the field value?
Ive tried the following but it gives me a PHP error:
<?php if($my_field == 'value1') { ?>
<h3>Value 1</h3>
<?php } else { ?>
<h3>Value 2</h3>
<?php } ?>
Thanks
You don't have to use PHP.
{if my_field == 'foo'}
Value 1
{if:else}
Value 2
{/if}
If you're planning on doing any EE tag processing within those conditionals, you shouldn't use the if:else syntax, as with it, the content between the conditionals will always be parsed, but just not displayed, which needlessly uses server resources and increases load time.
So in that case, use simple conditionals instead:
{if my_field == 'foo'}
Value 1
{/if}
{if my_field == 'bar'}
Value 2
{/if}
See: http://expressionengine.com/user_guide/templates/globals/conditionals.html
You can use ExpressionEngine's Conditional Global Variables to display your content, without having to use PHP in your templates.
Rewriting your example using native ExpressionEngine's Simple Conditional tags would result in the following:
{exp:channel:entries channel="channel_name" dynamic="off"}
{if "my_field" == "value1"}
Value 1
{/if}
{if "my_field" == "value2"}
Value 2
{/if}
{/exp:channel:entries}
You can use simple or complex conditionals anywhere in your templates, with the former being less resource expensive, but ExpressionEngine's Parse Order (PDF, 32 KB) may affect how they're evaluated and replaced.
In most cases, you'll need to ensure your custom fields and conditionals are within the {exp:channel:entries} tag loop for the values to be properly output and tested when the page is being built.

how to access cck checkbox value from views .tpl

Subject for advanced views theming:
1) Create CCK integer field "field_checkbox" - Single on/of checkbox
Allowed values
0|No
1|Yes
2) In views row-style .tpl
<?php print $fields['field_checkbox_value']->content ?>
doesn't print any value, why?
Other fields output fine.
Thank you in advance!
Resolved:
In views settings field output must be unformatted.
Output of above function return 1.
Useful for advanced views theming, for example:
<h3 class="title <?php if ($fields['field_checkbox_value']->content) print 'another-class' ?>">
<?php print $fields['title']->content ?>
</h3>

Resources