Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Someone firm with oscTemplate Class ?


Denzel

Recommended Posts

The browser will take care of only loading a script once if it's using the same url!

As for exicuting it will run as many times as it is called, so you will need to add logic to your script ( set flag if run and only run if flag is not set)

 

Link to comment
Share on other sites

Thanks Jc,

Unfortually I can't add logic, cause the Shopowner decides, if one of the added Boxes needs to add a Modal to Footer.

How can I add a flag inside a content module, which is accessable from an other module?

Link to comment
Share on other sites

10 hours ago, Denzel said:

How can I add a flag inside a content module, which is accessable from an other module?

Sorry maybe I misunderstood, perhaps you can supply more info or example of what you are trying to achive but....

If site owner is able to decide what is or is not loaded then simply seperate the scripts in question to hooks or header tags and explain these only need to be turned on if a box x is active.

If it's simply pulling more php from another file the just use "require_once"

But again without understanding clearly what is required this could all be wrong?

Anyway merry christmas and happy new year to you and everyone.....

 

Link to comment
Share on other sites

21 minutes ago, JcMagpie said:

If site owner is able to decide what is or is not loaded then simply seperate the scripts in question to hooks or header tags and explain these only need to be turned on if a box x is active.

I think this is sort of the reverse of what he wants. 

As I understand it, he wants one module to add the box from another module when the other module is not installed.  But if it is installed, he doesn't want to add it because it would already be there. 

Personally, I think it would be easier to just say, "If you want this box, please turn on this other module."  But that's not the question he's asking.  Perhaps it should be. 

In terms of the question, I think that looking in oscTemplate is too late.  By that time, the box is just a blob of HTML.  You'd have to look at the other module itself.  Is it installed and enabled to display?  Something like

if (isset($GLOBALS['cm_footer_information_links']) && $GLOBALS['cm_footer_information_links']->isEnabled()) {
  // do stuff if it is enabled
} else {
  // do stuff if it is not enabled
}

or reverse it

if (!isset($GLOBALS['cm_footer_information_links']) || !$GLOBALS['cm_footer_information_links']->isEnabled()) {
  // do stuff if it is not enabled
}

Note that this assumes that it would run after the modules are loaded.  Before that you'd have to check MODULE_CONTENT_INSTALLED for cm_footer_information_links.php. 

But I personally would not take this approach, as it relies on the exact name of the other module not changing.  I'd just ship it with its own copy, e.g. cm_footer_infopages_links, and tell store owners to install the one that they prefer.  Because that's what you have to do with any other module of similar purpose but differing name.  In fact, having this kind of logic makes it more difficult to manage the different possible boxes.  Because if someone created a new box for similar purpose, it would not be recognized.  And this module's configuration would imply that it should be. 

Sometimes it is better to code things the easy way and put the management burden on the user.  Because complexity can make it harder for the user to make good choices rather than easier.  In particular, what if someone wants to have two boxes of similar purpose both enabled at once?  As two entirely separate modules, that's easy.  But with this kind of code, they'd be stuck modifying code to get different behavior. 

Always back up before making changes.

Link to comment
Share on other sites

Sorry, sometimes I miss the english words 🙄 I'll try to explain better: I have updated the old Extra Infopages Addon, which adds a Linkbox to the Footersection of the Page. Then I've added the possibillity to let these Infopages popup in an Modal. There was a historic Pulldownmenu for the Pagetype, which is unused in my update. Now I plan to serve the Addon with two footer and two siteboxes and use the Pagetype to choose in which box the link should appear.

The Modal-Template is only added to footer_scripts, if the Shopowner adds a link to a box, which should open in Modal. If the Shopowner adds two Boxes, maybe Sitebox and Footerbox, and add Modallinks to both of them, I will suppress, adding the Modal-Template twice...

image.png.23aa52fbd418c6496f4a029f4736b8ce.png

image.png.5069b1a05c5f9daffc30c42f726faa65.png

Link to comment
Share on other sites

I think, I may add a value to $_SESSION. But is $_SESSION rebuild every pageload ? If Boxes are suppressed on some pages, I need to refill the variable every pageload...

Link to comment
Share on other sites

7 minutes ago, Denzel said:

The Modal-Template is only added to footer_scripts, if the Shopowner adds a link to a box, which should open in Modal. If the Shopowner adds two Boxes, maybe Sitebox and Footerbox, and add Modallinks to both of them, I will suppress, adding the Modal-Template twice...

Zahid's suggestion is that you just put the modal template in a separate module.  Then the separate module will only add the link once regardless.  The only bad part is that the user has to enable that module separately.  So it may be that sometimes they will forget. 

$_SESSION is not built every page load.  It is explicitly for sharing between pages. 

If you want something that is built per page and dies at the end of the page, try a static variable.  E.g.

function load_template_if_necessary() {
  static $template_needs_loaded = true;

  if ($template_needs_loaded) {
    load_template();
    $template_needs_loaded = false;
  }
}

Then load_template will get called at most once per page and you can call load_template_if_necessary as often as you want. 

But as Zahid pointed out, you could just as well do

include_once 'load_template.php';

and get the same effect. 

Always back up before making changes.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...