Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Views: Twig or no Twig?
03-11-2014, 02:22 AM
Post: #1
Views: Twig or no Twig?
twig:
Code:
<div class="table-responsive">
<table class="table table-striped table-hover {{ classes }}" {{ attributes }} >
{% if title %}
    <caption class="text-left">
        <h4>
            {{ title }}
        </h4>
    </caption>
{% endif %}

{% if headers|length > 0 %}
    <!-- header row -->
    <thead>
            <tr>
                
                {% for header in headers %}
                <th {% if header.class %} class="{{ header.class }}" {% endif %}{% if header.span %} colspan="{{ header.span }}"{% endif %} >
                    {{ header.content|e }}
                </th>
                {% endfor %}
                {% if columnCount > headerCount %}
                    {% for i in range(columnCount,headerCount) %}
                        <th class="no-sort"> </th>
                    {% endfor %}
                {% endif %}
            </tr>
    </thead>
{% endif %}
    <!-- table content -->
    <tbody>
        {% spaceless %}
        {% for row in rows %}
            <tr {% if row.htmlclass %}class="{{ row.htmlclass }}"{% endif %} {{ row.attributes }}>
                {% for column in row.columns %}
                        <t{{ column.isheader ? 'h' : 'd'}} {% if column.span >1 %} colspan="{{ column.span }}" {% endif %} {% if column.class %} class="{{ column.class }}"{% endif %}>
                            {% if column.link %}
                                <a href="{{ column.link }}" {{ column.attributes }} >
                                    {{ column.content|e }}
                                </a>
                            {% else %}
                                {{ column.content|e }}
                            {% endif %}
                        </t{{ column.isheader ? 'h' : 'd'}}>
                {% endfor %}
            </tr>
        {% endfor %}
        {% endspaceless %}
    </tbody>
</table>
</div>

No twig:

Code:
<div class="table-responsive">
<table class="table table-striped table-hover <?php echo $this->classes['table'];?>" <?php echo $this->attributes; ?>>
<?php
if(!empty($this->title)) { ?>
    <caption class="text-left">
        <h4>
            <?php echo $this->title; ?>
        </h4>
    </tr>
<?php
} //end title statement
if(!empty($this->headers)) { ?>
    <!-- header row -->
    <thead>
        <?php
        if (!empty($this->headers)) { ?>
            <tr>
                <?php
                foreach ($this->headers as $columnhead) {
                    echo '<th';
                    if ($columnhead['class']) {
                        echo ' class="' . $columnhead['class'] . '"';
                    }
                    if ($columnhead['span'] > 1) {
                        echo ' colspan="' . $columnhead['span'] . '"';
                    }
                    echo '>';
                    echo $columnhead['content']; ?>
                    </th>
                    <?php
                }
                ?><!-- <?php echo $this->columnCount . ' vs. ' . $this->headerCount; ?> --><?php
                if ($this->columnCount > $this->headerCount) {
                    $i = $this->headerCount;
                    while ($i < $this->columnCount) {
                        echo '<th class="no-sort"> </th>';
                        $i++;
                    }
                }
                ?>
            </tr>
        <?php } // end headers statement ?>
    </thead>
<?php
} // end thead if statement ?>
    <!-- table content -->
    <tbody>
        <?php
        foreach ($this->rows as $row) {
            ?>
            <tr <?php echo $row->htmlclass ? 'class="' . $row->htmlclass . '"' : '';
                      echo $row->attributes ? ' ' . $row->attributes : '';
            ?>>
                <?php
                foreach ($row->columns as $column) {
                    if ($column['isheader']) {
                        echo '<th';
                    } else {
                        echo '<td';
                    }
                    if ($column['span'] != 1) {
                        echo ' colspan="' . $column['span'] . '"';
                    }
                    if ($column['class']) {
                        echo ' class="' . $column['class'] . '"';
                    }
                    echo '>';
                    if ($column['link']) {
                        if ($column['attributes']) {
                            echo '<a href="' . $column['link'] . '" ' . $column['attributes'] . '>' . $column['content'] . '</a>';
                        } else {
                            echo '<a href="' . $column['link'] . '">' . $column['content'] . '</a>';
                        }
                    } else {
                        echo $column['content'];
                    }
                    if ($column['isheader']) {
                        echo '</th>';
                    } else {
                        echo '</td>';
                    }
                }
                ?>
            </tr>
            <?php
        }
        ?>
    </tbody>
</table>
</div>

Which one is better/WebERPier?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Views: Twig or no Twig? - serakfalcon - 03-11-2014 02:22 AM
RE: Views: Twig or no Twig? - Forums - 03-11-2014, 03:03 AM
RE: Views: Twig or no Twig? - agaluski - 03-11-2014, 03:17 AM
RE: Views: Twig or no Twig? - serakfalcon - 03-11-2014, 12:56 PM
RE: Views: Twig or no Twig? - icedlava - 03-11-2014, 02:15 PM

Forum Jump:


User(s) browsing this thread: 1 Guest(s)