Code Monkey home page Code Monkey logo

Comments (2)

kevinwhoffman avatar kevinwhoffman commented on June 30, 2024

I was looking for this example as well. Here's what I came up with:

<?php

    /* This example addresses the whitespace issue described at
       https://github.com/csswizardry/csswizardry-grids#classes-in-markup */

    $i = 1;
    $totalItems = 4; // total number of grid items

    while ( $i <= $totalItems ) {

        if ( $i == 1 ) {

            /* Echo opening tag of first item only.
               Subsequent opening tags handled at bottom of loop. */
            echo '<div class="grid__item  desk--one-fourth">';

        }





        // Content





        if ( $i < $totalItems ) {

            /* There are still more items after this item.
               Echo closing tag and opening tag of next item.
               Empty comment collapses white space. */
            echo '</div><!--

               --><div class="grid__item  desk--one-fourth">';

        } else {

            /* There are no more items after this item.
               Echo closing tag only. */
            echo '</div>';

        }

        $i++;
    }

Edit: Made a gist for future reference.

from csswizardry-grids.

csswizardry avatar csswizardry commented on June 30, 2024

Hi!

Sorry for letting this go stale :(

Try pasting the following into the codepad site:

<style>

.grid__item {
    display: inline-block;
}

.one-third {
    width: 33.333333333%;
}

</style>

<div class="grid">
<!--
<?php
    $items = array('foo', 'bar', 'baz');

    foreach ($items as $item) {
?>

--><div class="grid__item  one-third"><?= $item ?></div><!--

<?php
    }
?>
-->
</div>

Items from a loop without the need for a counter :)

from csswizardry-grids.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.