![]() |
Problem with parser - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Problem with parser (/showthread.php?tid=71581) Pages:
1
2
|
Problem with parser - Decibel150 - 08-31-2018 Hi guys, I have a problem that I can't solve right now, I'm using the parser library, and i need it to show a defined variable stored in the database in the view. PHP Code: $data = [ I have this stored in the database: "Buy on {site_name}" that I save it to seo_book_title View: Code: <meta property="og:description" content="{seo_book_title}" /> And the result is: "Buy on {site_name}" when the name defined above should appear on site_name. Sorry about my English, I'm Spanish. I hope you can help me, thank you and a greeting. RE: Problem with parser - Pertti - 08-31-2018 Haven't used it myself, but over here https://www.codeigniter.com/userguide3/libraries/parser.html#usage-notes looks like you need to set seo_book_title first in array, then follow-ups that might be in the first string after that. PHP Code: $data = [ RE: Problem with parser - Decibel150 - 08-31-2018 (08-31-2018, 08:57 AM)Pertti Wrote: Haven't used it myself, but over here https://www.codeigniter.com/userguide3/libraries/parser.html#usage-notes looks like you need to set seo_book_title first in array, then follow-ups that might be in the first string after that. No, it doesn't work, I don't know if I've been able to explain myself properly. I have this stored in my database: "Buy on {site_name}" and I want you to show me on the new label(seo_book_title) what I have in the database, It should work, since site_name is already defined, but it shows text as I have it in the database. RE: Problem with parser - ciadmin - 08-31-2018 You need to use the template parser, and not the normal views. $this->load('parser'); $this->parser->parse(YOUR_TEMPLATE_FILENAME,$data); RE: Problem with parser - Decibel150 - 08-31-2018 (08-31-2018, 10:51 AM)ciadmin Wrote: You need to use the template parser, and not the normal views. yes, that's what I'm doing, The problem is that in my database I save {site_name}, to show it with more text with {seo_title_books} and {site_name} it shows it as it is. RE: Problem with parser - ciadmin - 08-31-2018 You're going to have to show a bit more code, namely where you retrieve the data, before building the $data array, and perhaps the view fragment that isn't working properly. RE: Problem with parser - John_Betong - 08-31-2018 Try this: PHP Code: // ADDED quotes because variables not available Result: <meta property="og:description" content="$SeoBooks->title" /> RE: Problem with parser - Decibel150 - 09-01-2018 Nothing, no one seems to understand. I define the variables to be used in the view with parser: PHP Code: $ConfigurationSite = $this->MainModel->Configuration(); Model: PHP Code: public function Configuration() View: PHP Code: <html> In my database I have this string: Buy on {site_name}, If {site_name} was already defined above in $data, because when I show {seo_book_title}. {Site_name} is shown like this, and not with the name that was defined? RE: Problem with parser - ciadmin - 09-01-2018 The template parser is not recursive. You will have to use it once to substitute for site_name, and then again for tha main template, for instance something like... Code: $data = ...; RE: Problem with parser - Decibel150 - 09-01-2018 (09-01-2018, 07:44 AM)ciadmin Wrote: The template parser is not recursive. You will have to use it once to substitute for site_name, and then again for tha main template, for instance something like... It's still not working. I don't know how to get out of this, I'm thinking of having 2 different views and directly pass the values of parse hay, so as not to have to save anything in the database, Since I think it'll be easier and this is taking up a lot of my time. Thanks to all for the help. |