[solved] ctlModuleMaker previous/next syntax and columns

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
edented
Forum Members
Forum Members
Posts: 23
Joined: Sat Aug 29, 2009 4:24 am

[solved] ctlModuleMaker previous/next syntax and columns

Post by edented »

I'm trying to get the previous/next function on the detail pages.  I'm not sure what i'm checking for being loaded, and how. Can anyone show me the syntax?

not this.. {if $previous_item != ""}{$previous_item}{/if}

This is the hint of the available smarty variable $previous_item (if loaded)


...kicking and screaming into learning smarty
After this i have one more hurdle - list results into columns

Thanks!
Last edited by edented on Wed Sep 09, 2009 8:53 pm, edited 1 time in total.
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: ctlModuleMaker previous/next syntax

Post by plger »

the $previous_item variable does not contain a value, but an object, just like the $item variable. As the attributes are the same as $item, I did not enumerate them all a second time in the template help. But I assume what you are looking is something like :

Code: Select all

{if $previous_item}{$previous_item->detaillink}{/if}
Now, what kind of columns do you wish exactly?

Pierre-Luc
edented
Forum Members
Forum Members
Posts: 23
Joined: Sat Aug 29, 2009 4:24 am

Re: ctlModuleMaker previous/next syntax

Post by edented »

Thanks! That works. I take it i can make it say previous/next instead of the name.

As for the columns, I would like to be able to display the results (child elements of a category) in a more compact manor, rather than a single column.  Ideally i would like to be able to determine in the template that it has 3 columns (or 4 or 5 or 2).  Normally I've had this in a php loop, but i'm unsure of how this fits into the smarty world.

It would be great to see a fairly complex template to study.
Thanks again!
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: ctlModuleMaker previous/next syntax

Post by plger »

edented wrote:I take it i can make it say previous/next instead of the name.
Here you go :

Code: Select all

{if $previous_item}
<a href="{$previous_item->detailurl}">Previous</a>
{/if}
As to the columns, to be honest if I had to do it I would simply edit action.default.php and do it with php there before the template is processed. But if I wanted to do it with smarty (for the sake of pedagogics), I would try something like :

Code: Select all

{assign var="nbcol" value=2}
{assign var="nbpercol" value="false"}
{foreach from=$itemlist item="item" key="key" name="itemlistloop"}
	{if !$nbpercol}
		{math equation="ceil(itemcount / nbcol)" itemcount=$smarty.foreach.itemlistloop.total nbcol=$nbcol assign="nbpercol"}
		{if $nbpercol == 0}{assign var="nbpercol" value="1"}{/if}
	{/if}
	{if $key == 0 || ($key+1) is not div by $nbcol}
		{if $key != 0}</ul></div>{/if}<div style="float: left;"><ul>
	{/if}
	<li>{$item->name}</li>
	{if $smarty.foreach.itemlistloop.last}</ul></div>{/if}
{/foreach}
edented
Forum Members
Forum Members
Posts: 23
Joined: Sat Aug 29, 2009 4:24 am

Re: ctlModuleMaker previous/next syntax

Post by edented »

Hey that definitely points me in the right direction.  I will work with it later trying both areas and let you know how it goes.  Thanks again for your help.
edented
Forum Members
Forum Members
Posts: 23
Joined: Sat Aug 29, 2009 4:24 am

Re: ctlModuleMaker previous/next syntax

Post by edented »

No luck with the columns yet. I'm not much of a programmer
Trying the smarty template approach with floated div tags has some interesting results.

http://www.onrampstudios.com/cmsms/index.php?page=2column



Trying to insert/adjust the working column php code that i have into the action.defalut.php gave plenty wrong results with the table repeating. I'm not sure what to wrap it around. Here's the php. Ideally though, it would be great to not have to go edit the php to change the number of columns (assuming it can be made to work).

$num_cols = 2; // the number of columns
$total_records = count($itemlist);
$num_rows = ceil($total_records / $num_cols); // the number of rows
$num = 0; // don't change this value, this is the first number of each record inside a record set

echo "\n";
// next the loop for the table rows
for ($rows = 0; $rows \n";
    // this is the loop for the table columns
    for ($cols = 0; $cols alias />
".$description."
\n";

        } else { // show an empty cell
            echo " \n";
        }
        $num++; // raise the number by one for the next record
    }
    echo "\n"; // there are no more cols in this row, close the table row tag
}
echo "\n"; // end of the region = closing tag for the table element


Any ideas? Should this be a feature request? Thanks for any ideas
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: ctlModuleMaker previous/next syntax

Post by plger »

The problem with your floating divs is quite simple : because your pictures are in a list ( ul -> li ), and because your lists have no style or a style with a padding, there's a padding on the left of your pictures. Hence there's not enough space to fit all your columns. Just remove the padding from the list, or replace the and with , and your columns should be nice (provided that the images aren't too large).
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: ctlModuleMaker previous/next syntax

Post by plger »

Here:

Code: Select all

{assign var="nbcol" value=3}
{assign var="nbpercol" value="false"}
{foreach from=$itemlist item="item" key="key" name="itemlistloop"}
	{if !$nbpercol}
		{math equation="ceil(itemcount / nbcol)" itemcount=$smarty.foreach.itemlistloop.total nbcol=$nbcol assign="nbpercol"}
		{if $nbpercol == 0}{assign var="nbpercol" value="1"}{/if}
	{/if}
	{if $key == 0 || ($key+1) is not div by $nbcol}
		{if $key != 0}</div>{/if}<div style="float: left;">
	{/if}
	{$item->name}<br/>
	{if $smarty.foreach.itemlistloop.last}</div>{/if}
{/foreach}
<div style="clear: left;"></div>
(notice I added a div with clear left at the bottom, just to make sure the container would extend with the floating content)

(notice 2: you could give a width to your div to make sure they are all the same width... right now they will be as large as the largest image they contain)

Note that if you don't care about the order being left to right instead of top to bottom, you could simply do :

Code: Select all

{foreach from=$itemlist item="item"}
	<div style="float: left; padding: 10px;">{$item->name}</div>
{/foreach}
<div style="clear: left;"></div>
(ideally with a fixed width)
and they'd just stack horizontally and go to the next line once the first is full...
edented
Forum Members
Forum Members
Posts: 23
Joined: Sat Aug 29, 2009 4:24 am

Re: ctlModuleMaker previous/next syntax

Post by edented »

The simpler method works best for the moment.  Setting the div height as well as the width turned out to be important for the flow, unless the image heights were all the same. Now i can simply duplicate the template and adjust the widths to for however many columns i need for the category.

For future reference...
#############

{* set the div width to determine # of columns fitting in 800px #main-container. don't forget there might be padding*}

{foreach from=$itemlist item="item"}


{* display name, then image, or whatever content *}
{if $item->is_selected}class="active"{/if}{$item->detaillink}
{if $item->image != ""}detailurl}">
image->thumbnail}" alt=""/>
{/if}


{/foreach}


#############

Thanks Pierre-Luc for your immediate response and dedication. It is very much appreciated.
edented
Forum Members
Forum Members
Posts: 23
Joined: Sat Aug 29, 2009 4:24 am

Re: ctlModuleMaker previous/next syntax and columns

Post by edented »

Updating to version 1.8.9.1 seems to have broken previous/next continuity in detail pages.
http://www.onrampstudios.com/cmsms/index.php?page=landscapes


I have a query that calls for the children of a category. The results are now displayed on the front end (yea! soon i'll play with complex ordering).  And i can even get the nbperpage to work within that query (see below)
{cms_module module='ai_web' action='default' nbperpage='6' forcelist='0' searchmode='advanced' query='3' }


I seem to have a problem with regular page module calls and the nbperpage within a subset of records.
No results with this:
{cms_module module='ai_web' action='default' what='artworks(final level)' parent='Landscapes(subcategory)' forcelist='0' searchmode='advanced' limit='0' nbperpage='6' }

While this seems to ignore the 'Landscapes', calling all final level items while enforcing the nbperpage.
{cms_module module='ai_web' action='default' what='Landscapes' forcelist='0' searchmode='simple' limit='0' nbperpage='6' }


temporary example link
http://www.onrampstudios.com/cmsms/index.php?page=modulecalls


So it goes today.
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: [solved] ctlModuleMaker previous/next syntax and columns

Post by plger »

For simplicity,

Code: Select all

{cms_module module='ai_web' action='default' what='artworks' parent='Landscapes' forcelist='0' searchmode='advanced' limit='0' nbperpage='6'}
could very well be

Code: Select all

{cms_module module='ai_web' parent='Landscapes' nbperpage='6'}
(searchmode has no effect outside the search action, and your other parameters all have the default value)

The nbperpage / parent problem was a bug. I fixed it and uploaded 1.8.9.2 files.
edented
Forum Members
Forum Members
Posts: 23
Joined: Sat Aug 29, 2009 4:24 am

Re: [solved] ctlModuleMaker previous/next syntax and columns

Post by edented »

Working beautifully. Thanks for fixing that.
When i use the parent and nbperpage, the resulting page numbers reflect the entire number of children rather than just the subset.

An easy workaround:
create a query that calls a specific subset. Call the query id and use nbperpage, gives the right amount of pages (don't use the sort option as details come out of the item order).
User avatar
plger
Forum Members
Forum Members
Posts: 196
Joined: Wed Oct 15, 2008 10:38 am

Re: [solved] ctlModuleMaker previous/next syntax and columns

Post by plger »

Damn, I had fixed that but I forgot to add the parameter to the function... you can fix this by editing the module file (modulename.module.php), finding the line :

Code: Select all

function countsomething($tablename,$what="id",$where=array(),$wherestring=false,$wherevalues=array()){
And changing it to :

Code: Select all

function countsomething($tablename,$what="id",$where=array(),$wherestring=false,$wherevalues=array(),$parent=false){
Post Reply

Return to “Modules/Add-Ons”