SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast Chousho's Avatar
    Join Date
    Jun 2006
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    {noob question} I'm sure

    I see this many times in code I look at.

    What exactly is {variable} and how does it work in code? I see phrases that say "text text <a href="{URL"}>{LINK}</a>

    How do you make this work?

  2. #2
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,449
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    That's part of a templating system. The templating code parses the template looking for template variables like that and replaces them with the correct value. It's not part of the programming language but part of the application.

  3. #3
    SitePoint Zealot
    Join Date
    May 2006
    Location
    Phoenix, AZ
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the { } are also uses for in programming (php)...to include variable array elements and including inline code.

    PHP Code:
    $people = array("John","Jack","Joe");

    foreach(
    $people as $person){
    echo 
    "Hi, My Name is {$person}";
    }

    #This Will Output:
    #Hi, My Name is John
    #Hi, My Name is Jack
    #Hi, My Name is Joe
    #or

    echo "Hi, My Name is {$people[0]}, My Friends are {$people[1]} and {$people[2]}";

    #This will output:
    #Hi My Name is John, My Friends are Jack and Joe .. 
    Pretty much its an easier way of not having to do
    echo "Hi My Name is ".$person."!", makes your code cleaner too.
    Kreative Development
    Infinite Possibilities

  4. #4
    SitePoint Enthusiast Chousho's Avatar
    Join Date
    Jun 2006
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh sweet. Thank you very much! That makes sense when I see it in context like that.


Bookmarks

Posting Permissions

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