ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Dynamic tables?

October 26, 2011 5:59pm

Subscribe [2]
  • #1 / Oct 26, 2011 5:59pm

    Chriiiiso

    46 posts

    I’m trying to make some tables as seen on the old site and kind of amazed it’s so difficult across channels:
    http://www.classiccountryland.com/land-for-sale/oklahoma/lake-view-ranch.php

    Each “tract” is an entry in the “tract” channel.  The page is in the “property” channel.

    If you notice, each tract has different features such as power, water, etc.  Each page/property would have different features as well so I can’t make the table static.

    I’m trying to figure out how to display the correct number of columns, and populate them.  Tracts without all the features don’t leave empty cells where there should be.

    It needs to say
    “Property has x, y, and z so make three columns.  If tract has x, y, or z, say “MATCH”.  If tract does not have x,y, or z, leave the cell empty.”

    I’ve found a few ways (structure entries, phpstringfun,crazy if/elses) to the same dead end.  Any ideas?  Thanks a ton in advance.

  • #2 / Oct 27, 2011 1:29am

    Enviromed

    375 posts

  • #3 / Oct 27, 2011 2:56pm

    Chriiiiso

    46 posts

    Okay I think I figured it out, the solution was MUCH more simple than I imagined it would be.

    Using:
    PHPStringFun for an easy substr_count function so I can see if “a” is in “abc”.
    Structure because it’s what I’ve been using.  Used to set the entry_id for GWcode Categories to the current page.
    GWcode Categories to list only the categories associated with the parent.

    Ended up using categories.  Turns out you can put conditionals inside of categories tags, which led to my solution.  Applied the parents features as categories.  Applied the tract/listing/child features with a checkbox field so I can output all of its features with a single tag, because categories requires a pair.

    <table class="zebra-striped" id="pricingtable">
      <thead>
        <tr>
          <th>Tract</th>
          <th>Acres</th>
          <th>Price</th>
    {!-- a. Build the header columns using all categories assigned to the parent, this will make one th per category. --}
          {exp:channel:entries channel="property" status="not Closed"}
          {categories}
          <th>{category_name}</th>
          {/categories}
          {/exp:channel:entries}
          <th>Tract Information</th>
        </tr>
      </thead>
    {!-- b. Build down the rows, making a tr per child.  Parse inward for GWcode Categories. --}
      {exp:channel:entries channel="{structure:child_listing:short_name}" dynamic="off" status ="not Closed" parse="inward"}
      <tr>
        <td>{tract_number}</td>
        <td>{tract_acreage}</td>
    {!-- c. Now get the status of the child, and apply a class. --}
        <td><div id="tractstatustd" class="label {status}">{if status == "Available"}${tract_price}{if:elseif status == "Foreclosure"}<a href="http://{foreclosures_url}">Foreclosure</a>{if:else}Sold{/if}</div></td>
    {!-- d. Build out columns using all categories assigned to the parent like in "a."  This will make one td per category so they all line up. Parse inward. --}
        {exp:gwcode_categories entry_id="{structure:page:entry_id}" style="linear" parse="inward"}
        <td>
    {!-- e. Now check to see if the category name is in the childs features (a checkbox field), if it is, show the category image, if not, leave empty. --}
          {if "{exp:phpstringfun function="substr_count" par1="{cat_name}"}{utilities_and_features}{/exp:phpstringfun}" == "1"}YUP{if:else} {/if}</td>
        {/exp:gwcode_categories}
        <td><a href="http://{page_uri}">Tract Details</a></td>
      </tr>
      {/exp:channel:entries}
    </table>

    From that you could replace “YUP” to show the category image or whatever.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases