#1
  1. No Profile Picture
    Registered User
    SEO Chat Explorer (0 - 99 posts)

    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Creating a basic template engine...


    Hello everybody,
    I've started to work on building a template engine for a website since I need to seperate the logical units from the graphical units and template engines such as bgocled.com Smarty and TBS are way too big for what I really need: a very basic, simple template engine which manage simple tasks such as value reference and conditions.

    The value referencing has been quite easy, a simple str_replace would do the job correctly. Where it gets complicated is at the conditional management. I need it to make, for exemple:

    Code:
    [IF USER_STATUS_ADMIN]{SHOW_ADMIN_LINK}[ELSEIF USER_STATUS_WRITER]{SHOW_WRITER_LINK}[ELSEIF USER_STATUS_TESTER]{SHOW_TESTER_LINK}[ELSE]{SHOW_ALL_LINK}[/IF]
    turn into:

    Code:
    if $user_status_admin {
    echo $show_admin_link;
    }elseif $user_status_writer{
    echo $show_writer_link;
    }elseif $user_status_tester{
    echo $show_tester_link;
    }else{
    echo $show_all_link;
    }
    I must admit that I am quite rusted in PHP, so to reach this goal I first thought about using a regex to dispatch all my values... I used this regex:

    Code:
    /\[IF (.*?)\](.*?)(\[\/IF\]|\[ELSEIF (.*?)\](.*?)\[\/IF\])/i
    Before long I realized that I could only retrieve a single ELSEIF value. So I went with a string scaning method using this code:

    Code:
    $str = '[IF USER_STATUS_ADMIN]{SHOW_ADMIN_LINK}[ELSEIF USER_STATUS_WRITER]{SHOW_WRITER_LINK}[ELSEIF USER_STATUS_TESTER]{SHOW_TESTER_LINK}[ELSE]{SHOW_ALL_LINK}[/IF]';

    $pos = strpos($str, '[IF ');
    A new problem arose... Finding the first "[IF " was going fine, but finding the USER_STATUS_ADMIN between "[IF " and "]" was giving me trouble...

    So here I am now, which method I should focus my energy on and how to achieve my goal.

    Any help on the matter would be greatly appreciated,

    Thanks !
  2. #2
  3. No Profile Picture
    Registered User
    SEO Chat Explorer (0 - 99 posts)

    Join Date
    Dec 2011
    Posts
    2
    Rep Power
    0

    Unhappy


    No one can help me? This problem has troubled me for a long time!

Similar Threads

  1. Preview MSN similar to WISENUT SERPs - not so innovative after all
    By -search-engines-web in forum BING/Yahoo Search Optimization
    Replies: 19
    Last Post: Jun 23rd, 2006, 12:20 AM
  2. OH MY GOD!! seochat is #1 on New MSN Search for "Search engine optimization"
    By -search-engines-web in forum BING/Yahoo Search Optimization
    Replies: 38
    Last Post: Nov 17th, 2005, 06:06 AM
  3. I am confused.....plz help.
    By vinod2005 in forum Google Optimization
    Replies: 10
    Last Post: Aug 10th, 2005, 07:42 AM
  4. Need N/A SE Rank explained
    By Ramses357 in forum Google Optimization
    Replies: 21
    Last Post: Jul 12th, 2005, 09:06 PM

IMN logo majestic logo threadwatch logo seochat tools logo