Journal 2 theme
Hi everyone,
i have my OC in a subfolder of my domain. And then i got my domain with static pages, among them a "Privacy Policy" page. It is made out of different php files, one of them being the privacy policy text itself.
Now to make it one source only through out my web site, static pages and OC, i tried to use <? php include ("mypoliciyprivacytextfile.php"); ? > in the description box using code view, but opencart comments out the php code, my <? php include ("mypoliciyprivacytextfile.php"); ? > code becoming <!--? php include ("mypoliciyprivacytextfile.php"); ?-- >.
I found this topic viewtopic.php?f=202&t=202308&p=714911&h ... de#p714733 and this topic viewtopic.php?f=202&t=201321#p711081 but if they don't match my issue.
Is is possible to use <? php include ("file.php"); ?> in opencart description fields? If yes, then how?
Thank you all for your help
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
put your privacy-policy.twig twig file in there and use:
Code: Select all
{% include directory ~ '/default/template/includes/privacy-policy.twig' %}
of course this assumes you are using twig.
problem there is if you have multi-lingual privacy-policy files, twig wouldn't know what language we are in.
or as a general principle:
you can add to the controller:
Code: Select all
ob_start();
include('YOUR_INCLUDE_FILENAME');
$data['my_included_stuff'] = ob_get_clean();
Code: Select all
{{ my_included_stuff }}
Code: Select all
<?php echo $data['my_include_stuff']; ?>
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
thanks for your complete answer with 2 solutions. The first one is closer to what i am intending to do and I can see the second one is more a work around using a key that i can add in the templates if i mention the function in the corresponding controller, and i can make this through out my OC using only one source .
But actually i am trying to 'echo' in OC description fields some file from my own domain but from outside OC files. So my question should be more like, is there anyway to avoid description fields, for instance the one from privacy policy of my store (admin > catalog > information > Privacy Policy), to turn my <?php include ?> code into a <!--?php include ?--> comment ?
I guess it might be for some safety reason, but is there anyway to clear security? And if yes, what might be the issues doing so?
I do not know which part is making it comments, perhaps the editor or the save function.
I use includes in the html module by adding {{ filename }} to the description in admin.
I have the include files in an include directory.
I then use:
Code: Select all
// get an include file instead of the entered html if indicated by {{ filename }} pulled from the includes directory
$html = $data['description'];
$btoken = '{{';
$etoken = '}}';
$final_html = '';
$begin = '';
$end = '';
if (stristr($html,$btoken) and stristr($html,$etoken)) {
while (stristr($html,$btoken) and stristr($html,$etoken)) {
$bpos = strpos($html,$btoken);
$epos = strpos($html,$etoken);
$begin = mb_substr($html,0,$bpos);
$end = mb_substr($html,$epos+strlen($btoken));
$include_file = mb_substr($html,$bpos+strlen($btoken),$epos-$bpos-strlen($etoken));
ob_start();
include(DIR_INCLUDES . $include_file);
$include_html = ob_get_clean();
$final_html .= $begin.$include_html;
$html = $end;
}
$data['description'] = $final_html . $end;
}
The code basically replaces {{my_include_html_filename}} with the content of the file "my_include_html_filename" in the DIR_INCLUDES directory if such a reference exists.
you could do the same with description in information.php after:
Code: Select all
$data['description'] = html_entity_decode($information_info['description'], ENT_QUOTES, 'UTF-8');
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
thank you to clear that up, and i understand then i cannot make it per language as you mentioned in a previous post.
One last thing now, i guess i can have the file source out of my OC files right? as i can setup any directory if i follow you.
With only the twig include twig you cannot (unless you use separate twigs per language):
Code: Select all
{% include directory ~ '/default/template/includes/privacy-policy.twig' %}
For the other solutions you can define any directory in your filesystem as DIR_INCLUDES.
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
Could someone tell me where the "get an include file instead of the entered html.." code goes?
Thanks!
letxobnav wrote: ↑Sat Sep 14, 2019 6:33 pmwell, no, you cannot add php to a description field unless you use the very unsafe "eval()" function on it.
I do not know which part is making it comments, perhaps the editor or the save function.
I use includes in the html module by adding {{ filename }} to the description in admin.
I have the include files in an include directory.
I then use:
in the description field I simply have {{my_include_html_filename}}Code: Select all
// get an include file instead of the entered html if indicated by {{ filename }} pulled from the includes directory $html = $data['description']; $btoken = '{{'; $etoken = '}}'; $final_html = ''; $begin = ''; $end = ''; if (stristr($html,$btoken) and stristr($html,$etoken)) { while (stristr($html,$btoken) and stristr($html,$etoken)) { $bpos = strpos($html,$btoken); $epos = strpos($html,$etoken); $begin = mb_substr($html,0,$bpos); $end = mb_substr($html,$epos+strlen($btoken)); $include_file = mb_substr($html,$bpos+strlen($btoken),$epos-$bpos-strlen($etoken)); ob_start(); include(DIR_INCLUDES . $include_file); $include_html = ob_get_clean(); $final_html .= $begin.$include_html; $html = $end; } $data['description'] = $final_html . $end; }
The code basically replaces {{my_include_html_filename}} with the content of the file "my_include_html_filename" in the DIR_INCLUDES directory if such a reference exists.
you could do the same with description in information.php after:
just make sure you define the DIR_INCLUDES constant in config.php or use the full path.Code: Select all
$data['description'] = html_entity_decode($information_info['description'], ENT_QUOTES, 'UTF-8');
In one of the controllers. What pages are you trying to change?
Users browsing this forum: No registered users and 122 guests