Jump to content
Latest News: (loading..)
ArtcoInc

Can two modules use the same template?

Recommended Posts

And, if so, can that template be modular and/or Admin configurable?

For example, in Edge, there is the Navbar Account module and the Content Footer Account module that both do essentially the same thing. Could they share a common template file? And, could the shared contents be configurable through Admin (ie: add or delete links)?

Malcolm


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get the latest community-supported responsive "Frozen" release here

Share this post


Link to post
Share on other sites

I just ran into this again, helping someone add a 'link' to a page they added. I wasted a bunch of time having them edit the /boxes/information files instead of the /content/footer/information_links files.

Both display a list of links that presumably should be the same. After all, they both have the same default links ...

(yes, I suppose that there may be someone that wants different links in different areas of their store, but ...)

Anyway, could it be possible to have both use the same template?


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get the latest community-supported responsive "Frozen" release here

Share this post


Link to post
Share on other sites
11 minutes ago, ArtcoInc said:

Anyway, could it be possible to have both use the same template?

The template file contents is usually doing the visual part so I think it should be possible. Isn't there a path to the template file inside the module file? 

Did you try to change that path to point to the one and same template file?

Share this post


Link to post
Share on other sites

@Tsimi

I have not tried this ... I just wanted to ask if anyone had already done this, or knew of problems with doing this. Thanks, though :biggrin:

Edited by ArtcoInc
typo

If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get the latest community-supported responsive "Frozen" release here

Share this post


Link to post
Share on other sites
2 hours ago, ArtcoInc said:

I have not tried this ... I just wanted to ask if anyone had already done this, or knew of problems with doing this. Thanks, though :biggrin:

@ArtcoInc Malcolm I haven't tried this either but if you are using two different modules and are just calling a common template is should be possible by just referencing the correct template file as Lambros pointed out.  Give it shot and let us know.

Dan

Share this post


Link to post
Share on other sites

There is no reason why not.  But...

Imagine you have a template like this (edge, card acceptance box);

<div class="panel panel-default">
  <div class="panel-heading"><?php echo MODULE_BOXES_CARD_ACCEPTANCE_BOX_TITLE; ?></div>
  <div class="panel-body text-center"><?php echo $output; ?></div>
</div>

and you have a template like this (edge, specials box);

<div class="panel panel-default">
  <div class="panel-heading">
    <?php echo '<a href="' . tep_href_link('specials.php') . '">' . MODULE_BOXES_SPECIALS_BOX_TITLE . '</a>'; ?>
  </div>
  <div class="panel-body text-center">
    <?php echo '<a href="' . tep_href_link('product_info.php', 'products_id=' . $random_product['products_id']) . '">' . tep_image('images/' . $random_product['products_image'], htmlspecialchars($random_product['products_name']), SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a><br /><a href="' . tep_href_link('product_info.php', 'products_id=' . $random_product['products_id']) . '">' . $random_product['products_name'] . '</a><br /><del>' . $currencies->display_price($random_product['products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) . '</del><br /><span class="productSpecialPrice">' . $currencies->display_price($random_product['specials_new_products_price'], tep_get_tax_rate($random_product['products_tax_class_id'])) . '</span>'; ?>
  </div>
</div>

You can see that they are broadly similar.

What you could do is have ONE template for both as so;

<div class="panel panel-default">
  <div class="panel-heading">
    <?php echo $box_title; ?>
  </div>
  <div class="panel-body text-center">
    <?php echo $box_content; ?>
  </div>
</div>

But then in both module files, you would need to make $box_title and $box_content.

Does that make sense ?

My idea of "modular" is that each module does its own thing; module file, language file, template file.
This way, things are extremely flexible.

It's unfortunate that the shopowner you helped the other day did not give all the data you need in his first post.

Addendum

If you think about it...the following pages all follow a similar "template"; 

  • index.php -> product listing
  • products_new.php
  • specials.php
  • advanced_search_result.php

All of these use the "template":  includes/modules/product_listing.php

 


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest current code (community-supported responsive 2.3.4.1BS Edge) here

 

Share this post


Link to post
Share on other sites

@burt

I recognized that there were enough differences in the way the two templates were formatted to not be able to use one template for both modules. I suppose one could complicate things with if conditions, etc ... but would it be worth it?

<shrug>

Probably not.

Thank you, though.


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get the latest community-supported responsive "Frozen" release here

Share this post


Link to post
Share on other sites

@burt

(thinking out loud here ...)

Using, for example, the /boxes/information files and the /content/footer/information_links files ...

IF the 'data' (the link to each module/page, and the description/title/heading/whatever-you-call-it for each one) was in a database table, both templates could draw the same 'data' from the database. The template could then do what it's supposed to ... to style and format the information.

Another bonus would be that as developers create new add-ons, these could auto-populate the database, making the new add-on available with no additional edits or changes.

A concern, though, might be the additional database hits with EVERY.SINGLE.PAGE.LOAD.

Thoughts?


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get the latest community-supported responsive "Frozen" release here

Share this post


Link to post
Share on other sites

@ArtcoInc Malcolm....what's  wrong with having two different template files?  It is pretty simple that way and easy to understand.

Dan

Share this post


Link to post
Share on other sites

@Dan Cole In my second post above, I mentioned that I was assisting someone here in the forum, and wasted a lot of time having them edit the wrong template.

Actually, it all boils down to the case of having to remember to change both templates when adding something to a shop. That's all.

Malcolm


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get the latest community-supported responsive "Frozen" release here

Share this post


Link to post
Share on other sites

I do that all the time and I'm told it gets worse.  :wacko:

Like you I usually try to find a way to avoid it in the future but sometimes I just have to chalk it up to "having one of those moments again".  

Dan

Share this post


Link to post
Share on other sites

My idea of modularity is that each module is self contained, hence has its own template file.

I understand that my idea of modularity is not to the taste of everyone...


This is a signature that appears on all my posts.  
IF YOU MAKE A POST REQUESTING HELP...please state the exact version
of osCommerce that you are using. THANKS

 
Get the latest current code (community-supported responsive 2.3.4.1BS Edge) here

 

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×