Jump to content

Create a custom page with a custom template


Recommended Posts

Hi,
I want to create a new page on my site and add a specific template , ie with different columns of the rest of the site and a slideshow but not yet properly etendi how can anyone explain me how can I create a specific layout for a page?

Link to comment
Share on other sites

The easiest way is to do it with a module: http://nemops.com/creating-new-pages-in-prestashop/#.VSj6gPnQqr0

 

See the setTemplate part.

 

Otherwise, create a new controller in the controllers/ folder, then add the template file to your template folder, using the same $this->setTemplate()

Ho nice, but I wanted to make a query about a specific product category? with this code i can display all products.

 

$products_partial = Product::getProducts($this->context->language->id, 0, 5, 'name', 'asc');

$products = Product::getProductsProperties($this->context->language->id, $products_partial);

$this->context->smarty->assign(array( 'products' => $products, 'homeSize' => Image::getSize('home_default') )); 

 

how can i do it with this query??

Link to comment
Share on other sites

Oh in that case use $category->getProducs(); on a category object

Ref:

 

public function getProducts($id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $random = false, $random_number_products = 1, $check_access = true, Context $context = null)
Link to comment
Share on other sites

 

Oh in that case use $category->getProducs(); on a category object

 

Ref:

 

 

public function getProducts($id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $random = false, $random_number_products = 1, $check_access = true, Context $context = null)

So, i was using that:

 

$products_partial = Product::getProducts($this->context->language->id, 0, 5, 'name', 'asc');

$products = Product::getProductsProperties($this->context->language->id, $products_partial);

$this->context->smarty->assign(array( 'products' => $products, 'homeSize' => Image::getSize('home_default') )); 

 

and now you are saying to change the code to:

 

public function initContent()
    {        
 
parent::initContent();
 
$category->getProducs($id_lang,0,5);
$this->setTemplate('deign10.tpl');
    }
 
public function getProducts($id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $random = false, $random_number_products = 1, $check_access = true, Context $context = null)
}
 
 
i didnt get it... 

I'm used to working with SQL queries, for me it is easier to understand. can give me a help in this role? I'm doing something wrong, I get it, but still do not understand how this works.

 

 

Edited by Rest95 (see edit history)
Link to comment
Share on other sites

No no, That last one was for your reference
 

parent::initContent();
 
$category->getProducs($id_lang,0,5);
$this->setTemplate('deign10.tpl');
    }


That's almost correct, just add $category = new Category(1);
before, and use your category id instead of 1. Remember to also use $this->context->smarty->assign
Link to comment
Share on other sites

 

No no, That last one was for your reference

 

parent::initContent();
 
$category->getProducs($id_lang,0,5);
$this->setTemplate('deign10.tpl');
    }

 

That's almost correct, just add $category = new Category(1);

before, and use your category id instead of 1. Remember to also use $this->context->smarty->assign

 

Just get a blank page  :mellow: 

 

Even loads the template

 

parent::initContent();
$category = new Category(20);
$category->getProducs($id_lang,0,5);
$this->context->smarty->assign;
$this->setTemplate('deign10.tpl');

 

I am doing something wrong...

Link to comment
Share on other sites

definitely

 

$this->context->smarty->assign;

 

This is a method, not a property :)

 

$this->context->smarty->assign('something', $variable);

 

Anyway, still print a blank page :| i will past all the class.

 

Class testmoduleAllproductsModuleFrontController extends ModuleFrontController
{
public function init()
{
    $this->page_name = 'Design 10'; // page_name and body id
$this->display_footer = false;
$this->display_column_left = false;
$this->display_header = false;
$this->display_column_right = false;
    parent::init();
}   
 
public function initContent()
    {        
parent::initContent();
$id_lang = Configuration::get('PS_LANG_DEFAULT');
$category = new Category(20);
$category->getProducs($id_lang,0,5);
 
$this->context->smarty->assign('category_design10',$category);
$this->setTemplate('design10.tpl');
    }
 
 
}
Link to comment
Share on other sites

Always turn on error reporting when developing :) It will tell you what's wront

 

apart from that, you are not getting products

 

$products = $category->getProducs($id_lang,0,5);
and 


$this->context->smarty->assign('category_design10',$products);

Link to comment
Share on other sites

hahaha... i'm so dumb jesus... 

now it works...

Really thanks man... you save my day :D

 

but, to print products in tpl file i can use the code like in product-list.tpl?
 

{if isset($products)}
    <!-- Products list -->
    <ul id="product_list" class="clear">
    {foreach from=$products item=product name=products}
        <li class="ajax_block_product {if $smarty.foreach.products.first}first_item{elseif $smarty.foreach.products.last}last_item{/if} {if $smarty.foreach.products.index % 2}alternate_item{else}item{/if} clearfix">
            <div class="left_block">
                {if isset($comparator_max_item) && $comparator_max_item}
                    <p class="compare">
                        <input type="checkbox" class="comparator" id="comparator_item_{$product.id_product}" value="comparator_item_{$product.id_product}" {if isset($compareProducts) && in_array($product.id_product, $compareProducts)}checked="checked"{/if} /> 
                        <label for="comparator_item_{$product.id_product}">{l s='Select to compare'}</label>
                    </p>
                {/if}
            </div>
            <div class="center_block">
                <a href="{$product.link|escape:'htmlall':'UTF-8'}" class="product_img_link" title="{$product.name|escape:'htmlall':'UTF-8'}">
                    <img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'home_default')}" {if isset($homeSize)} width="{$homeSize.width}" height="{$homeSize.height}"{/if} />
                    {if isset($product.new) && $product.new == 1}<span class="new">{l s='New'}</span>{/if}
                </a>
                <h3><a href="{$product.link|escape:'htmlall':'UTF-8'}" title="{$product.name|escape:'htmlall':'UTF-8'}">{$product.name|escape:'htmlall':'UTF-8'|truncate:35:'...'}</a></h3>
                <p class="product_desc"><a href="{$product.link|escape:'htmlall':'UTF-8'}" title="{$product.description_short|strip_tags:'UTF-8'|truncate:360:'...'}" >{$product.description_short|strip_tags:'UTF-8'|truncate:360:'...'}</a></p>
            </div>
            <div class="right_block">
                {if isset($product.on_sale) && $product.on_sale && isset($product.show_price) && $product.show_price && !$PS_CATALOG_MODE}<span class="on_sale">{l s='On sale!'}</span>
                {elseif isset($product.reduction) && $product.reduction && isset($product.show_price) && $product.show_price && !$PS_CATALOG_MODE}<span class="discount">{l s='Reduced price!'}</span>{/if}
                {if (!$PS_CATALOG_MODE AND ((isset($product.show_price) && $product.show_price) || (isset($product.available_for_order) && $product.available_for_order)))}
                <div class="content_price">
                    {if isset($product.show_price) && $product.show_price && !isset($restricted_country_mode)}<span class="price" style="display: inline;">{if !$priceDisplay}{convertPrice price=$product.price}{else}{convertPrice price=$product.price_tax_exc}{/if}</span><br />{/if}
                    {if isset($product.available_for_order) && $product.available_for_order && !isset($restricted_country_mode)}<span class="availability">{if ($product.allow_oosp || $product.quantity > 0)}{l s='Available'}{elseif (isset($product.quantity_all_versions) && $product.quantity_all_versions > 0)}{l s='Product available with different options'}{else}{l s='Out of stock'}{/if}</span>{/if}
                </div>
                {if isset($product.online_only) && $product.online_only}<span class="online_only">{l s='Online only!'}</span>{/if}
                {/if}
                {if ($product.id_product_attribute == 0 || (isset($add_prod_display) && ($add_prod_display == 1))) && $product.available_for_order && !isset($restricted_country_mode) && $product.minimal_quantity <= 1 && $product.customizable != 2 && !$PS_CATALOG_MODE}
                    {if ($product.allow_oosp || $product.quantity > 0)}
                        {if isset($static_token)}
                            <a class="button ajax_add_to_cart_button exclusive" rel="ajax_id_product_{$product.id_product|intval}" href="{$link->getPageLink('cart',false, NULL, "add&id_product={$product.id_product|intval}&token={$static_token}", false)}" title="{l s='Add to cart'}"><span></span>{l s='Add to cart'}</a>
                        {else}
                            <a class="button ajax_add_to_cart_button exclusive" rel="ajax_id_product_{$product.id_product|intval}" href="{$link->getPageLink('cart',false, NULL, "add&id_product={$product.id_product|intval}", false)}" title="{l s='Add to cart'}"><span></span>{l s='Add to cart'}</a>
                        {/if}                       
                    {else}
                        <span class="exclusive"><span></span>{l s='Add to cart'}</span><br />
                    {/if}
                {/if}
            </div>
        </li>
    {/foreach}
    </ul>
    <!-- /Products list -->
{/if}
Edited by Rest95 (see edit history)
Link to comment
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
×
×
  • Create New...