Announcement

Collapse
No announcement yet.

Possible to store phrase variables in database?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Possible to store phrase variables in database?

    Is it possible to store phrases as variables in the database and show them in templates? I tested it but it's not working.

    I did the following simple steps:

    1.) Stored a phrase like "{vb:rawphrase tl_reg_open}" in a table
    2.) Grabbed the table with query
    3.) Registered the db array
    4.) Inserted the var into the template

    But it's not working for me. I've only the complete phrase (i.e. "{vb:rawphrase test}") on my site, not the contain phrasetext.

    Thanks in advance.

  • #2
    You probably have to insert compile_template("{vb:rawphrase test}") into the template.

    You will need this line to use compile_template:
    Code:
     require_once(DIR . '/includes/adminfunctions_template.php');

    Comment


    • #3
      Thanks for your reply. But's not working.

      Part in my template:

      Code:
      <td>compile_template("{vb:raw array.name}")</td>
      The array.name var contains {vb:rawphrase test}.

      And btw. congrats to your supporter status here.

      Comment


      • #4
        Thanks.

        I didn't mean to put it in your template... actually I am/was a little confused.

        How are you inserting {vb:raw array.name} into a template?

        I meant something like

        PHP Code:

        $template 
        str_replace ("<br />""<br />" compile_template("{vb:raw array.name}"), $template); 
        You have to run it before it is actually inserted.

        The above is just example code, no meant to actually work.

        Comment


        • #5
          Hm, i don't understand what you exactly mean, sorry. I checked the compile_template() function. If i'm correct, it's for templates not for vars?
          I don't understand for what i need the str_replace function. I try to make it more clear.

          My database table:



          part of my php file which creates the template and get datas from db:

          PHP Code:
          $query $db->query_read("SELECT * FROM table WHERE id = xy");
          $array $db->fetch_array($query);

          // construct the rows  
                          
          $templater vB_Template::create('tl_template');
                          
          $templater->register('array'$array);
                          
          $trackerbit .= $templater->render(); 
          And at least my template:

          HTML Code:
          <td>{vb:raw array.name}</td>
          That's it, i have no idea how i can display the phrase value in front of the phrase.

          Comment


          • #6
            I'm thinking you're going to need to put the real value of the phrase into the array, not that name of the phrase itself into the template.

            I'm sure what else you are doing but based on what you have shown this should work.

            PHP Code:
            $query $db->query_read("SELECT * FROM table WHERE id = xy"); 
            $array $db->fetch_array($query); 

            if (
            $array['id'] == 2)
              
            $array['name'] = $vbphrase['tl_reg_open'];

            // construct the rows   
                            
            $templater vB_Template::create('tl_template'); 
                            
            $templater->register('array'$array); 
                            
            $trackerbit .= $templater->render(); 
            -edited php code-
            Last edited by Joe D.; Sun 16th Oct '11, 11:15am.

            Comment


            • #7
              Thanks. You think that's the only solution? Looks not really clean for me. But that should work, thanks again.

              Comment


              • #8
                I know it's not ideal but that's my only guess... I'm not sure your needs and goals but I would probably setup my database like this-
                I would use a phrase for all the values in the database (AKA "Invite Only" and "Completely Closed.")

                So my database table would be:

                id | name
                1 | phrase_invite_only
                2 | tl_reg_open
                3 | phrase_completely closed

                and then the php

                PHP Code:
                $query $db->query_read("SELECT * FROM table WHERE id = xy"); 
                $array $db->fetch_array($query); 

                $tempname $array['name'];

                $array['name'] = $vbphrase["$tempname"];

                // construct the rows   
                                
                $templater vB_Template::create('tl_template'); 
                                
                $templater->register('array'$array); 
                                
                $trackerbit .= $templater->render(); 

                Comment


                • #9
                  The idea is much better. Thank you.
                  Wondering a little bit why it's not possible with vbulletin to use phrases in the db.

                  Comment


                  • #10
                    It's not the problem they are coming from the database, it's that you are inserting text value into a template variable, it only gets evaluated once.

                    Comment

                    widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
                    Working...
                    X