Results 1 to 12 of 12

Thread: IF statements are now in the templates!

  1. #1
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default IF statements are now in the templates!

    see http://www.nicecoder.com/community/s...&threadid=2056

    as a followup to the above post, I have added a template parsing function to the linkcoder code.

    Of particular note is the ability to use IF-THEN-ELSE statements within the templates themselves thereby controlling the HTML at the time the template is displayed based on the data from the link itself.-

    You can see it here http://www.indexuhelp.com/link_coder/cat_list.php

    Take a look at the New Products subcategory (cat_id=5) in the Business to Business category

    Cal you pick out the Editor's Pick links?

    Here is the template file itself:
    Code:
    <%LOOP links%> 
    
    <table cellpadding='0' cellspacing='0' align="center" border='1' 
    width='100%' bordercolor="#ffffff" bordercolorlight="#000000">
    <tr>
    <td>
    <table cellpadding='4' cellspacing='0' border='0' width='100%'>
    <tr>
    <td align=left>
    <img src="http://www.indexuhelp.com/images/icons/dots.gif" width=13 height=13 ALIGN=absmiddle>&nbsp;
    linkcoder has search-engine friendly links
    <a class=lblack href="detail.php/id/<%link_id%>.html"><%title%></a> -  <%date%> 
    
    An example an IF statment to control what info to display in the template 
    - New= 
    <%IF new==1%>Yes 
    <%ELSE%>No
    <%/IF%> 
    
    - Pick= 
    <%IF pick==1%>Yes
    <%ELSE%>No
    <%/IF%> 
    
    - Top Rated= 
    <%IF top_rated==1%>Yes
    <%ELSE%>No
    <%/IF%> 
    
    - Updated= 
    <%IF updated==1%>Yes 
    <%ELSE%>No 
    <%/IF%> 
    
    <br>
    </td>
    <td>&nbsp;<!-- <div align="right"><b><%review_image%></b> - <b><%rating_image%></b></div> -->
    </td>
    </tr>
    
    <tr>
    <td 
    
    An example an IF statment to control how the template itself can 
    be controlled based on information from the link itself 
    <%IF pick==1%> style="background-color:#CCCCFF;"
    <%ELSE%>style="background-color:#D3D3D3;"
    <%/IF%> 
    
     colspan="2">
    
    <%description%>
    <%top_rated%>
    </td>
    </tr>
    <tr>
    <td style="background-color:#D3D3D3; border-top: dotted 1px black;" colspan="2">
    hits: <%hits%> - Contact: <%contact_name%> - Email: <%email%>
    </td>
    </tr>
    </table>
    
    </td>
    </tr>
    </table>
    <!-- spacer -->
    <BR>
    <%/LOOP%>
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

  2. #2
    Join Date
    May 2004
    Location
    New Zealand
    Posts
    600

    Default awesome...

    Interesting way of doing it mate....

    Would it be easy to have differant detail pages.... and then have say a item in the link database which gets the IF statement..... and then depending on the result it displays that item in whichever detail page applys?

  3. #3
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default

    if i understand what you are trying to do:
    Code:
    IF data_one=something
     use detail template one
    end if
    
    IF data_one=something_else
     use detail template two
    end if
    
    IF data_one=something_last
     use detail template three
    end if
    that would work
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

  4. #4
    Join Date
    May 2004
    Location
    New Zealand
    Posts
    600

    Default yep thats the one

    exactly... but im not sure where to put the code, As in which file should it be in..... (or maybe even files....) any ideas mate.

  5. #5
    Join Date
    May 2004
    Location
    New Zealand
    Posts
    600

    Default hmmmmm

    Where would I be best to put the code, before the detail page, because basically I want everyone to fill in all details, but I only want it to show in detail2.htm if they have a full listing.. or detail1.htm if they dont have a full listing...

    So the IF statement kinda needs to be before the detail page gets called I think.

    I could be wrong though... any ideas ?

  6. #6
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default

    the IF statement mentioned in my original thread if part of the the LinksCoder MOD and not available in the standard INDEXU templates.

    to do that in INDEXU you would need to modify the detail.php file. See the following for an example.

    http://www.nicecoder.com/community/s...light=template
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

  7. #7
    Join Date
    May 2004
    Location
    New Zealand
    Posts
    600

    Default Cheers ESM

    Cheers for that, If I had added a new field in the link table called Adtype would I just change it from Cat == to Adtype ==

    or would I have to add it as a variable also?
    Last edited by ezykiwi; 06-10-2004 at 12:17 PM.

  8. #8
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default

    you will need to add something like the following in detail.php

    Code:
      $links_obj = new clsLink;
      $links_obj->InitDB($dbServer, $dbHostname, $dbUsername, $dbPassword, $dbName);
    
      
    global $conn;
      $query = "select Adtype from idx_link where link_id = $link_id";
      $result = $conn->Execute($query);
      $Adtype = $result->Fields(Adtype);
    then add the code to select the template
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

  9. #9
    Join Date
    May 2004
    Location
    New Zealand
    Posts
    600

    Default Hmmmmm puzzle :)

    Call to a member function on a non-object in line 77 which is....

    $Adtype = $result->Fields(adtype);

    any ideas?

  10. #10
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default

    make sure spell adtype the way it is typed in the table including the same case

    also add the print line shown below

    Code:
      $links_obj = new clsLink;
      $links_obj->InitDB($dbServer, $dbHostname, $dbUsername, $dbPassword, $dbName);
    
      
    global $conn;
      $query = "select Adtype from idx_link where link_id = $link_id";
      print "<br>query= $query";
      $result = $conn->Execute($query);
      $Adtype = $result->Fields(Adtype);
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

  11. #11
    Join Date
    May 2004
    Location
    New Zealand
    Posts
    600

    Default Cheers ESM...

    Cheers ESM....

    Working perfectly now.... I noticed that there was similar code up the top of the page... in detail.php

    so I just added it in there...

    $query = "select title, suspended, adtype from idx_link where link_id = '$id'";
    $result = $conn->Execute($query);
    $link_title = $result->Fields("title");
    $suspended = $result->Fields("suspended");
    $adtype = $result->Fields("adtype");


    and its working a treat... cheers for the help

  12. #12
    Join Date
    Apr 2003
    Location
    Atlanta GA
    Posts
    3,395

    Default

    glad it works for you
    esm
    "The older I get, the more I admire competence, just simple competence, in any field from adultery to zoology."

    .

Similar Threads

  1. Templates
    By richhead in forum v3.2
    Replies: 9
    Last Post: 09-09-2003, 02:44 AM
  2. Templates for sale
    By Veg in forum Templates
    Replies: 26
    Last Post: 08-09-2003, 08:41 AM
  3. Templates
    By richhead in forum v5.x
    Replies: 19
    Last Post: 07-07-2003, 02:53 AM
  4. NEW INDEXU THEME Templates
    By Hart_House in forum Templates
    Replies: 8
    Last Post: 02-27-2003, 07:36 PM
  5. New Templates Question...
    By amanda in forum Templates
    Replies: 1
    Last Post: 02-05-2002, 02:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •