Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts

    Using double brackets to extract info

    I am trying to do comments on my profiles where people can leave a short comment, however it would be easy except that my page is setup in a template, so it uses arrays. So doing this {{name}} would show the persons name it pulls it from another file where it's broken down into code.

    Now with this template it will only extract info from the users table. I want to extract from the comments table. What can I put in the other file so that I can use {{comments}} in my template file?
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #2
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    *bump* been 24 hours
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #3
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by masterofollies View Post
    *bump* been 24 hours
    24 hours and pyschic abilities are still in short supply. You've not mentioned which software you're using or given any hint, (or example), as to what the existing code looks like.

  • #4
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Software? there is no software, it's PHP.

    library.php
    PHP Code:
    if ($items == true)
                {
                    
    $userrow['itemslist'] .= '<a href="index.php?x=item:' $itemsrow['id'] . '"><font color=black>' $itemsrow['name'] . ' (' $unique[$itemsrow['id']] . ')</font></a><br />';
                } 
    template.php
    PHP Code:
    Items: {{itemslist}} 
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #5
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by masterofollies View Post
    Software? there is no software, it's PHP.
    PHP is a programming language. You write a PHP script and you create a programme, i.e: software. That snippet of code was about as much use as a chocolate fireguard, btw.

    With regards to your question, you code in the format relevant for your template engine.

  • #6
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts

  • #7
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Quote Originally Posted by MattF View Post
    PHP is a programming language. You write a PHP script and you create a programme, i.e: software. That snippet of code was about as much use as a chocolate fireguard, btw.

    With regards to your question, you code in the format relevant for your template engine.
    Software would be an exe file, I-tunes, MS Word, Dreamweaver, I find that as software. PHP is a programming language.

    Right and for my template it's setup to read from the users table. I need help figuring out how to add a different table into it, or how I can get it to read from the template.

    At the beginning of the profile it reads
    PHP Code:
    $template = <<<PROFILE 
    and at the end of the file it shows
    Code:
    PROFILE;
    Last edited by masterofollies; 02-28-2010 at 07:16 PM.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #8
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Quote Originally Posted by masterofollies View Post
    Software would be an exe file, I-tunes, MS Word, Dreamweaver, I find that as software. PHP is a programming language.
    Strictly speaking, PHP is both a piece of software an a programming language. But that is completely off-topic so both of you please stop arguing about it.
    Quote Originally Posted by masterofollies View Post
    Right and for my template it's setup to read from the users table. I need help figuring out how to add a different table into it, or how I can get it to read from the template.
    We would have to look at a lot more of your site's code to be able to tell you specifically where to add the new tag, but if you check to see where it is being replaced you can probably figure it out yourself. I believe kbluhm was trying to give you a subtle hint with his post.

  • #9
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by Inigoesdr View Post
    Strictly speaking, PHP is both a piece of software an a programming language. But that is completely off-topic so both of you please stop arguing about it.
    It's not off-topic. If he either posted the code for one of the scripts where this process takes place, or mentioned which CMS, (or similar), *software* he's using, then we'd all find it a bit easier to have the faintest idea regarding the question.

  • #10
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    There is no CMS, this is hand coded.

    I've looked and looked at the script to find it, but I cannot find the spot where it converts it, or a template. I know these scripts inside and out. Part of it was coded by someone else, which is why I am trying to find it.

    str_replace doesn't work in this.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #11
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Quote Originally Posted by masterofollies View Post
    str_replace doesn't work in this.
    In principal it's exactly what you're looking for. You have described a token parser that takes the content of your page and replaces certain items:
    Quote Originally Posted by masterofollies
    So doing this {{name}} would show the persons name it pulls it from another file where it's broken down into code.

    Now with this template it will only extract info from the users table. I want to extract from the comments table. What can I put in the other file so that I can use {{comments}} in my template file?
    So, -somewhere- you're doing a str/preg/etc. replace of some sort. And you haven't posted any code that shows us how you're doing that, so we can't really help you with that, can we?

  • #12
    Senior Coder kbluhm's Avatar
    Join Date
    Apr 2007
    Location
    Philadelphia, PA, USA
    Posts
    1,509
    Thanks
    3
    Thanked 258 Times in 254 Posts
    Quote Originally Posted by Inigoesdr View Post
    I believe kbluhm was trying to give you a subtle hint with his post.
    Bingo

    Quote Originally Posted by masterofollies View Post
    str_replace doesn't work in this.
    Doesn't it?
    PHP Code:
    foreach ( $userrow as $key => $value )
    {
        
    $template str_replace'{{' $key '}}'$value$template );


  • #13
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by masterofollies View Post
    There is no CMS, this is hand coded.

    I've looked and looked at the script to find it, but I cannot find the spot where it converts it, or a template. I know these scripts inside and out. Part of it was coded by someone else, which is why I am trying to find it.
    You'll have a template class or suchlike. Do a grep for '$template)' and find out which file does the processing.


    str_replace doesn't work in this.
    The template engine will most likely have removed any unused template tags. Without some full code to look at though, there's not really that much anyone can suggest.

  • #14
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    I found this. It does use a str_replace, but the PHP manual examples had nothing to do with what I need, so I didn't see it was helpful in this case.

    PHP Code:
    function gettemplate($templatename)
    // SQL query for the template.

        
    $filename "templates/" $templatename ".php";
        include_once(
    $filename);
        return 
    $template;
    }

    function 
    parsetemplate($template$array)
    // Replace template with proper content.
        
    $array = (array) $array;
        foreach (
    $array as $a => $b)
        {
            
    $template str_replace("{{{$a}}}"$b$template);
        }
        return 
    $template;

    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #15
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Good, now search for where parsetemplate() is called, and find out where the second argument($array) is defined. After you do that all you have to do is add your new entry to that array before parsetemplate() is called for each comment.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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