15

Twig counter PHP equivalent

 3 years ago
source link: https://www.codesd.com/item/twig-counter-php-equivalent.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Twig counter PHP equivalent

advertisements

Hello I would like do something like that with my Twig template

<?php
    for( $i = 0; $i <= 5; $i++ ) {
        // Not display the first number
        if( $i <= 1 ) {
            continue;
        }
        // Displaying numbers from 2 to 5
        echo $i ,'<br/>';
    }
?>

How can I do that ?

Thanks for your help.


From the documentation you can use this to iterate numbers

{% for i in 0..10 %}
    * {{ i }}
{% endfor %}

Also from the documentation you can add conditions like this

<ul>
    {% for user in users if user.active %}
        <li>{{ user.username|e }}</li>
    {% endfor %}
</ul>

So if you combine the two you end up with something like this.

{% for i in 0..5 if i<= 1 %}
    * {{ i }}
{% endfor %}

Untested but should work. THe documentation : http://twig.sensiolabs.org/doc/tags/for.html

Related Articles

What is the PHP equivalent of MySQL UNHEX ()?

What is the PHP equivalent of MySQL's UNHEX()? For instance, the following query and PHP function should provide the same value. SELECT UNHEX(c1) AS unhexed_c1 FROM table; $unhexed_c1=PHPs_UNHEX_Equivalent($c1); There's a built-in function called hex

Netbeans syntax highlighting for volt (twig) and php in phtml files

I'm working with Phalcon in Netbeans. I see I can use twig plugin for template highlighting for volt files. I am using phtml files and want highlighting for volt (twig) and php. Is this possible? Also related - Netbeans keeps duplicating my phtml vie

The PHP equivalent of Java's Character.getNumericValue (char c)?

Is there a PHP equivalent of Java's Character.getNumericValue(char c)?Use the intval() function. This will not handle letters or roman numerals the same way, but you could create your own method to do that for those cases. It will handle standard dig

PHP Equivalent of Ruby's Rescue

don't have enough reputation to tag this properly (ruby,PHP,socket,rescue) I haven't practised my PHP in a long time, as I've been doing more Ruby scripting. I'm kind of embarrassed to ask for help with this. I know, in Ruby, that I can use rescue to

Is there a PHP equivalent of Rails migrations?

Is there a PHP equivalent of Rails migrations? Looking for a good solution for configuring schema changes locally and then automatically bumping them to the server without losing data.Ruckusing Migrations is a "Database Migrations" framework for

Is there a PHP-equivalent function for the Python os.path.normpath () file?

Is there a PHP equivalent function to the Python os.path.normpath()? Or how can i get the exactly same functionality in PHP?Here is my 1:1 rewrite of normpath() method from Python's posixpath.py in PHP: function normpath($path) { if (empty($path)) re

Is there a PHP equivalent to Compass?

From my understanding, Compass only works with Ruby. Is there a PHP equivalent to Compass?Compass actually works great for PHP projects. I've used it on several CakePHP and Symfony projects. Compass is built with Ruby, so you need Ruby on your machin

PHP equivalent password hash of following code .NET

I don't really want to dump some code and expect answers but this is a pretty lengthy function that hashes a password in order to later compare it to the database-stored value. I have seen posts where people wasted time trying to recreate what they c

What is the PHP equivalent of the VB class stream?

As discribed on this MSDN page http://msdn.microsoft.com/en-us/library/system.io.stream.aspx What would be the PHP equivalent? Is it even possible to do the three things listed on that page under remarks Streams involve three fundamental operations:

Is there anything in PHP equivalent to LINQ in C #?

Is there something in PHP equivalent to LINQ in C#?There is PHPLinq - LINQ for PHP.

PHP: equivalent to the MySQL function SUBSTRING_INDEX?

I love the SUBSTRING_INDEX function in MySQL, especially because you can use negative indexes to start searching from the right side of the string. Is there an equivalent of this function in PHP? (or an easy way to do it with a bit of code)There's no

What is the PHP equivalent of Javascript undefined?

My assumption followed by question based on the assumption: Javascript has null and undefined. You can set a variable to be null, implying it has no value, or you can set it to undefined, implying that it isn't known whether it has a value or not - i

PHP equivalent to fb.getloginstatus

using the FB PHP SDK... what is the equivalent method of the FB JS SDK method: fb.getLoginStatus I'm looking for something like: $facebook->getLoginStatus() I haven't been able to find it after looking through the entire FB PHP Class. I basically wan

Cookies counter php

I'm trying to do this counter for cookies. The cookies give the right values when I visit the site more than once but for first visit, it always tell me that the cookies(both) are not set. I'm new at PHP so I'm not sure if I missed something. The coo

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK