ledaanbieder Posted October 6, 2013 Share Posted October 6, 2013 Does anybody know how to insert variables (non-html) code into the CMS pages? We are running a multishop with shared CMS-pages, but we want our sitename to be variable in these pages. One of the the variables should be $SHOP_NAME in a standaard CMS page with the privacy policy. Pages like these often use the shop name many times. <?php .... ?> will not work because of the HTML output... Who can help us? Arjan 't Hart webmaster LEDaanbieder.nl (http://www.ledaanbieder.nl) cms.tiff Link to comment Share on other sites More sharing options...
gonebdg - webindoshop.com Posted October 6, 2013 Share Posted October 6, 2013 How if using jquery ?inside the CMS content you just have to write an unique html element e.g : ... cms content ... <span class="store_name"></span> ... continue cms content Then with jquery, you can change the html element with the store name. var storeName = '{$shop_name}'; $('.store_name').text(storeName); You can also use jquery html(), append(), prepend(), after(), before(), etc But remember, you should create an unique html element with unique css class and make sure no other html element using this css class. Link to comment Share on other sites More sharing options...
ledaanbieder Posted October 7, 2013 Author Share Posted October 7, 2013 Thx gonebdg. I will try this. Where should I change the HTML element? In what file? Link to comment Share on other sites More sharing options...
stevejohn Posted October 8, 2013 Share Posted October 8, 2013 As far as I know, it's not possible, nor is it sensible, to do this all from the CMS page. You're best bet would be to create widget. Widgets are reusable template tags that are very similar to the blocks used in the Magento layout system. Once your widget is made, you can then call the widget in the CMS page with a product option,[spam-filter]widget type="mywidgets/productname" product_id="1"[spam-filter], and modify the widget's output based on the product id entered. The tutorial I've linked to is very good, and should be a great starting point. Link to comment Share on other sites More sharing options...
vekia Posted October 8, 2013 Share Posted October 8, 2013 well in my opinion gonebdg solution will work, but it is a bit "tricky". if i were you i will create some modification, for example: in cms controller add function to replace cms contents. $cms->content=str_replace("{MY_VARIABLE}",SHOP_NAME,"$cms->content"); then in cms editor just use {MY_VARIABLE} and it will be changed automatically to value defined in str_replace function you can define as many aliases as you want Link to comment Share on other sites More sharing options...
ledaanbieder Posted October 8, 2013 Author Share Posted October 8, 2013 (edited) Thanks Vekia! Do you mean change CmsController.php and add this function? /** * Add function to use {my_variable} in CMS content */ public function replaceContent() { $cms->content=str_replace("{MY_VARIABLE}",SHOP_NAME,"$cms->content"); } And where do I have to define this function to work like you described? Thanks in advance! Edited October 8, 2013 by ledaanbieder (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted October 8, 2013 Share Posted October 8, 2013 hello open CmsController.php file, you've got there function: public function initContent() at the end of this function you've got: $this->setTemplate(_PS_THEME_DIR_.'cms.tpl'); right before this code add this: if (isset($this->cms)){ $this->cms->content=str_replace("{MY_VARIABLE}",configuration::get('PS_SHOP_NAME'),"{$this->cms->content}"); } then in cms edit page use {MY_VARIABLE} like i show below: effect in front office: *my shop is named "Test Shop" 3 Link to comment Share on other sites More sharing options...
ledaanbieder Posted October 9, 2013 Author Share Posted October 9, 2013 Oh thanks soooooo much Vekia! It works like a charm in all of our stores! Greets, Arjan 't Hart ledaanbieder.nl Link to comment Share on other sites More sharing options...
vekia Posted October 9, 2013 Share Posted October 9, 2013 you're welcome glad to hear that i could help you a little in this case im going tom mark this topic as [solved] with regards, Milos Link to comment Share on other sites More sharing options...
scorpionsworld Posted November 5, 2013 Share Posted November 5, 2013 I don't want to be a pain in the ass Vekia, But why suggest changing the core controller instead of replacing the core controller's function with an override controller? E.g. placing the complete initContent function in root/override/controllers/front/CmsController.php and include the extra str_replace code there. That way, an update of the PS software won't up the changes made. P.S. Great solution by the way. Link to comment Share on other sites More sharing options...
vekia Posted November 6, 2013 Share Posted November 6, 2013 you've got right. but sometimes writing about overrides is... pain in the ass Link to comment Share on other sites More sharing options...
SkyHiRider Posted March 5, 2014 Share Posted March 5, 2014 I don't want to be a pain in the ass Vekia, But why suggest changing the core controller instead of replacing the core controller's function with an override controller? E.g. placing the complete initContent function in root/override/controllers/front/CmsController.php and include the extra str_replace code there. That way, an update of the PS software won't up the changes made. P.S. Great solution by the way. Could you share an override file for prestashop 1.4.11 ? Link to comment Share on other sites More sharing options...
prestatent Posted March 10, 2014 Share Posted March 10, 2014 (edited) Well done Vekia. This is exactly what I'm looking for, with one difference. I want to replace links in my CMS pages with a path to the base folder. I'm having a small issue in that the link is ending up like this: http://www.mysite.com/gb/content/{MY_VARIABLE}/6-food#/categories-king_edward_potatoes My code looks like this: $this->cms->content=str_replace("{MY_VARIABLE}",configuration::get('PS_BASE_DIR'),"{$this->cms->content}"); Any ideas? Thank you. Edited March 10, 2014 by prestatent (see edit history) Link to comment Share on other sites More sharing options...
vekia Posted March 10, 2014 Share Posted March 10, 2014 use this: configuration::get('PS_BASE_DIR').$this->cms->content Link to comment Share on other sites More sharing options...
prestatent Posted March 10, 2014 Share Posted March 10, 2014 (edited) Thanks Vekia Do I not have to use MY_VARIABLE in the code? What I'm looking to achieve is a link like this: http://www.mysite.com/gb/6-food#/categories-king_edward_potatoes but what is appearing is a link like this: http://www.mysite.com/gb/content/{MY_VARIABLE}/6-food#/categories-king_edward_potatoes Edited March 10, 2014 by prestatent (see edit history) Link to comment Share on other sites More sharing options...
prestatent Posted March 11, 2014 Share Posted March 11, 2014 One more thing on this. How would I get the url for my shop for multistore: eg shop 1 = http://www.mysite.com shop 2 = http://www.mysite.com/vip Link to comment Share on other sites More sharing options...
prestatent Posted March 11, 2014 Share Posted March 11, 2014 Resolved now. Thanks for your help again Vekia. Link to comment Share on other sites More sharing options...
vekia Posted March 11, 2014 Share Posted March 11, 2014 hello i missed your replies, now i get notification that you replied but i see that problem is solved may i know where the problem was? or you just tried code that i suggested to use? Link to comment Share on other sites More sharing options...
prestatent Posted March 11, 2014 Share Posted March 11, 2014 Prestashop 1.5.4.1 Hi Vekia I created an override for the CMS Controller file, based on your code, as follows: class CmsController extends CmsControllerCore{ public function initContent() { parent::initContent(); if (isset($this->cms)) { $this->cms->content = str_replace("{MY_VARIABLE}", '../', "{$this->cms->content}"); } $this->setTemplate(_PS_THEME_DIR_.'cms.tpl'); }} This fix resolved linking from CMS pages to product pages. Thank you once again for your help. Link to comment Share on other sites More sharing options...
SkyHiRider Posted March 12, 2014 Share Posted March 12, 2014 Prestashop 1.5.4.1 Hi Vekia I created an override for the CMS Controller file, based on your code, as follows: class CmsController extends CmsControllerCore { public function initContent() { parent::initContent(); if (isset($this->cms)) { $this->cms->content = str_replace("{MY_VARIABLE}", '../', "{$this->cms->content}"); } $this->setTemplate(_PS_THEME_DIR_.'cms.tpl'); } } This fix resolved linking from CMS pages to product pages. Thank you once again for your help. Will this override work in PS 1.6 ? Link to comment Share on other sites More sharing options...
vekia Posted March 12, 2014 Share Posted March 12, 2014 the same as for 1.5.x 1.6 is based on 1.5 core. Link to comment Share on other sites More sharing options...
Christiaan_01 Posted February 16, 2015 Share Posted February 16, 2015 Hi Vekia, Adding the variable in CMS works great! Do you have an idea on how to do this for category pages (category description) and also for meta descriptions? Regards, Christiaan Link to comment Share on other sites More sharing options...
tharacus Posted April 28, 2015 Share Posted April 28, 2015 Hi,I'm using multistore. If I use the code from Vekia with variable PS_SHOP_NAME, I see the name of multistore, but I would like to see the name of one of my store. I would like to use the name which is in ps_shop in DB, not the name which is in ps_configuration in DB. Is that possible? Link to comment Share on other sites More sharing options...
ssneck Posted December 13, 2015 Share Posted December 13, 2015 (edited) Hi guys! I used Vekia instruction in this thread to use my variable in product description. Thanks very much for this code! At this moment I can put my {MY_VARIABLE} to product description (via html editor) and it will show default product category. I used this code in ProductController.php and it work good for me! if (isset($this->product)){ $this->product->description=str_replace("{MY_VARIABLE}",($this->category->name),"{$this->product->description}"); } Can you please help me to do the same thing but with certain product Feature Value?In used code from this this topic, but it only help to use feature value variable which I can put only to .tpl file. But I need to use certain features value variables via html editor in product description.I'm not a coder and do not know how it can be done correctly, but I'm believe it possible. I need create same product descriptions where different words are features values. I want only set needed feature values for this product and in description will be shown these words automatically. I have big quantity of products and all time I need to add new products. Copy / paste work make me crazy )) Please help me to get correct code, if you can).Thank you in advance! ) Edited December 13, 2015 by ssneck (see edit history) Link to comment Share on other sites More sharing options...
ssneck Posted December 20, 2015 Share Posted December 20, 2015 Answer to my question If you want to use certain feature as variable in you product description you need to put code to ProductController.php as described here by Adolphemattos in post #6 and then put this code: if (isset($this->product)){ $feature_var = $features_by_key[1]['value']; $this->product->description=str_replace("{FEATURE_VAR}","{$feature_var}","{$this->product->description}"); } right before this line: $this->setTemplate(_PS_THEME_DIR_.'product.tpl'); now you can write {FEATURE_VAR} in product description and in fron office it will show feature with id1. Link to comment Share on other sites More sharing options...
ietax Posted March 31, 2017 Share Posted March 31, 2017 Hi guys! I used Vekia instruction in this thread to use my variable in product description. Thanks very much for this code! At this moment I can put my {MY_VARIABLE} to product description (via html editor) and it will show default product category. I used this code in ProductController.php and it work good for me! if (isset($this->product)){ $this->product->description=str_replace("{MY_VARIABLE}",($this->category->name),"{$this->product->description}"); } Can you please help me to do the same thing but with certain product Feature Value? In used code from this this topic, but it only help to use feature value variable which I can put only to .tpl file. But I need to use certain features value variables via html editor in product description. I'm not a coder and do not know how it can be done correctly, but I'm believe it possible. I need create same product descriptions where different words are features values. I want only set needed feature values for this product and in description will be shown these words automatically. I have big quantity of products and all time I need to add new products. Copy / paste work make me crazy )) Please help me to get correct code, if you can). Thank you in advance! ) Hi, it works for me. But i would like to insert 2-3 variables. price meta_title category name how can I do it? thanks 1 Link to comment Share on other sites More sharing options...
ifs-net Posted January 29 Share Posted January 29 Hello, How can I add some variables to sales terms page pls ? I mean at the page that opens when you click sales terms. I want to add customer name , adress etc at terms page. Link to comment Share on other sites More sharing options...
ifs-net Posted January 31 Share Posted January 31 On 3/11/2014 at 2:19 PM, prestatent said: Prestashop 1.5.4.1 Hi Vekia I created an override for the CMS Controller file, based on your code, as follows: class CmsController extends CmsControllerCore { public function initContent() { parent::initContent(); if (isset($this->cms)) { $this->cms->content = str_replace("{MY_VARIABLE}", '../', "{$this->cms->content}"); } $this->setTemplate(_PS_THEME_DIR_.'cms.tpl'); } } This fix resolved linking from CMS pages to product pages. Thank you once again for your help. can I use the code for prestashop 1.7.8 pls ? Link to comment Share on other sites More sharing options...
ifs-net Posted February 1 Share Posted February 1 On 3/11/2014 at 2:19 PM, prestatent said: Prestashop 1.5.4.1 Hi Vekia I created an override for the CMS Controller file, based on your code, as follows: class CmsController extends CmsControllerCore { public function initContent() { parent::initContent(); if (isset($this->cms)) { $this->cms->content = str_replace("{MY_VARIABLE}", '../', "{$this->cms->content}"); } $this->setTemplate(_PS_THEME_DIR_.'cms.tpl'); } } This fix resolved linking from CMS pages to product pages. Thank you once again for your help. does not work for 1.7.8 version , anybody knows how can I use that for prestashop 1.7.8 pls ? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now