Problem with parser |
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.
Haven't used it myself, but over here https://www.codeigniter.com/userguide3/l...sage-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 = [
(08-31-2018, 08:57 AM)Pertti Wrote: Haven't used it myself, but over here https://www.codeigniter.com/userguide3/l...sage-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.
You need to use the template parser, and not the normal views.
$this->load('parser'); $this->parser->parse(YOUR_TEMPLATE_FILENAME,$data);
(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.
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.
Try this:
PHP Code: // ADDED quotes because variables not available Result: <meta property="og:description" content="$SeoBooks->title" />
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?
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 = ...;
(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. |
Welcome Guest, Not a member yet? Register Sign In |