dynamic content for templates

Dynamic content for templates, a forum discussion on Jojo CMS. Join us for more discussions on Dynamic content for templates on our General Discussion forum.

Back to Forum Index : Back to General Discussion   RSS
creativechaos

4 May 2008
Posts: 7

Hi all,

I am trying to work out a way to have the ability to allow the editing of a content section from within the admin.

The content is not a page, but just a section within the page (just a sponsors section for logos).

I am already using the articles plugin for a latest news section and had considered using this, but since the content is essentially just html content I want to be able to edit from the admin I thought I could perhaps set this up as a page and remove all navigation linkage to this page.

I then tried adding code to global.php as follows:

/* Extract Data From Sponsors Page */
$sponsorcode = Jojo::selectQuery("SELECT pg_body FROM {page} WHERE pageid=67");
$smarty->assign('sponsors', $sponsorcode[0]['pg_body']);


Then in my sponsors.tpl page I add {sponsors}


This works great in extracting the data I want, however I have a few questions.

1. I am assuming that this is executing the select query every time a page loads so not the most optimum solution considering this sponsor section is only on the home page.

2. Is there any way I can convert the above to a function so as to make it more generic?

I tried:

static function _getpgbody($selectpageid)
{
/* Extract Data From Sponsors Page */
$sponsorcode = Jojo::selectQuery("SELECT pg_body FROM {page} WHERE pageid=?", $selectpageid);
$smarty->assign('sponsors', $sponsorcode[0]['pg_body']);
return $sponsorcode[0]['pg_body']);
}

but it seems I can't call the function from the template file.

Any pointers would be greatly appreciated.



Harvey

Core Developer

Harvey

4 May 2008
Posts: 327

To restrict it to just the homepage, you can use the following code in global.php

if ($page->page['pageid'] == 1) {
$somecontent = 'Your code here';
$smarty->assign('somecontent', $somecontent);
}

This will only run the query on the homepage.

But, there are other alternatives. What you have suggested is a nice simple way of approaching the problem, but you might want to consider a basic sponsors plugin which makes managing sponsors a little easier.

Consider the sponsor logos at the bottom of www.siriussports.co.nz, a site I did a while ago. Those sponsor logos are placed there from a database, I have attached an image of the admin screen.

If this kind of interface would be useful, I could easily enough comment the plugin up and post the code for you. Should be a good simple example to reverse engineer and figure out how it's done.

The logic goes something like this...
  • Store a record for each sponsor in a database table
  • in global.php, SELECT * FROM sponsor ORDER BY something
  • Assign the query resultset to Smarty
  • Loop through the resultset in Smarty using a foreach or section loop
  • Create the HTML for the image / link dynamically. Images are resized dynamically too, which makes it easier to manage (client has already changed his mind about the size of those logos a couple of times).


If you don't want to go to the trouble of making a plugin, then the approach you already have sounds fine - of course it's not all 'bundled up' nicely, and if the pageid changes then things will break.
Harvey

Core Developer

Harvey

4 May 2008
Posts: 327

Another "slightly nasty" way is to embed PHP into the Smarty template, something like this...

{php}$sponsorcode = Jojo::selectQuery("SELECT pg_body FROM {page} WHERE pageid=?", $selectpageid);
echo $sponsorcode[0]['pg_body'];{/php}


Smarty can deal with regular PHP if it's inside {php}{/php} tags. You may need to deal with some variable scope issues via the "global" keyword, but it should work as a low-tech way of doing it.

We don't generally like using {php} tags - it feels a bit like cheating.

And one more approach...

With Jojo it's easy to add additional fields onto any admin page. Say you needed an extra text editor field for "sidebar content" or similar (custom sidebar video here). This would work fine for content that is different on each page, not so great if a piece of content is used on many pages.
creativechaos

5 May 2008
Posts: 7

Harvey,

Thanks for the tips.

I did look at creating a plugin for both the sponsors and also an events one which I think would be very handy. This is one of those "need to have yesterday" projects so I guess I'm kind of cheating here by just using a page record for these subsections, but as I said it does seem to work great so for now I'm happy with this. Will look at the events and sponsors plugins as I familiarize myself with the software.

Fantastic work on this CMS guys... The simplicity yet flexibility is astounding.

synfield

24 Jul 2008
Posts: 43

Could I please get a copy of this plugin. It would be a good platform for understanding how the backend gui customisation works.

Could you also resurrect the "sidebar templates" video as the video file is no longer available.

Cheers.
Back to Forum Index : Back to General Discussion   RSS
You must be logged in to post a reply



You need to Register or Log In before posting on these forums.