Jump to content

News Modules


Recommended Posts

Hello

 

I have make a news modules for PS 1.5, the script works fine.

 

but I´m wondering one thing...

 

I dont whant to have it i the left or the right side, I whant to have a link from the blocktopmenu

for the service i can offer our customer I use: index.php?id_cms=7&controller=cms&id_lang=1

 

but I dont now How i can access the blocknews.tpl in the modules...

 

PLEASE HELP.....

Link to comment
Share on other sites

You can edit the blocktopmenu's tpl directly, and place the hardcoded link there (or, if you use a separate page, use getModuleLink('modulename', 'controllername')

 

Be sure you add the link as a list item inside .sf-menu

Link to comment
Share on other sites

Hello...

 

I have manage to create the page in the modules/blocknews/controller/front called news.php

So now when i go to index.php?fc=module&module=blocknews&controller=news i see a emty page...

 

But now i need to get the info from the blocknews.tpl in the modules/blocknews/

 

How do i do that.

 

the news.php in the front is this

 

<?php
if (!defined('_PS_VERSION_'))
exit;


Class blocknewsNewsModuleFrontController extends ModuleFrontController 
{ 

}

Link to comment
Share on other sites

You can't get the info from the tpl, you've got to take it from the module itself, by calling the same funzions used when displaying the block. Use them here instead, and refer to the module as $module->functionname();

Link to comment
Share on other sites

Well, i don't know your module so i can't really help you with functions I don't know (and of which I don't even know the name)

 

it really depends on your module, just use the same you use in the hookLeftColumn function for example, but be sure you use $module and not $this when referring to the module itself

Link to comment
Share on other sites

this is my HookleftColumn

 

public function hookLeftColumn($params)
   {
       $news = $this->getLinks();

       $this->smarty->assign(array(
           'blocknews_news' => $news,
           'title' => Configuration::get('PS_BLOCKNEWS_TITLE', $this->context->language->id),
           'url' => Configuration::get('PS_BLOCKNEWS_URL'),
           'lang' => 'text_'.$this->context->language->id
       ));
       if (!$news)
           return false;
       return $this->display(__FILE__, 'blocknews.tpl');
   }

   public function hookRightColumn($params)
   {
       return $this->hookLeftColumn($params);
   }

   public function hookHeader($params)
   {
       $this->context->controller->addCSS($this->_path.'blocknews.css', 'all');
   }

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

Try this:

    $news = $this->module->getLinks();

    $this->context->smarty->assign(array(
	    'blocknews_news' => $news,
	    'title' => Configuration::get('PS_BLOCKNEWS_TITLE', $this->context->language->id),
	    'url' => Configuration::get('PS_BLOCKNEWS_URL'),
	    'lang' => 'text_'.$this->context->language->id
    ));
    if (!$news)
	    return false;
    return $this->setTemplate('blocknews.tpl');

 

Note that the template must follow the folder structure I highlighted in my tut

Link to comment
Share on other sites

I have the error on...

 

This is what i have done now...

 

news.php in the modules/blocknews/controllers/front

<?php
if (!defined('_PS_VERSION_'))
   exit;

Class blocknewsNewsModuleFrontController extends ModuleFrontController
{
$news = $this->module->getLinks();

           $this->context->smarty->assign(array(
                   'blocknews_news' => $news,
                   'title' => Configuration::get('PS_BLOCKNEWS_TITLE', $this->context->language->id),
                   'url' => Configuration::get('PS_BLOCKNEWS_URL'),
                   'lang' => 'text_'.$this->context->language->id
           ));
           if (!$news)
                   return false;
           return $this->setTemplate('blocknews.tpl');

}

 

blocknews.tpl in the modules/blocknews/views/templates/front


Link to comment
Share on other sites

now i did like this:

 

in the blocknews/views/templates/front/blocknews.php

<!-- Block links module -->
{foreach from=$blocknews_news item=blocknews_new}
{if isset($blocknews_new.$lang)}
<div class="newsletter-archives-block">
<div class="newsletter-archives-block-calendar">
   <span class="calendar-month">{$blocknews_new.month|escape}</span>
   <span class="calendar-day">{$blocknews_new.day|escape}</span>
   <span class="calendar-year">{$blocknews_new.year|escape}</span></div>
<div class="newsletter-archives-block-content">
<h3>{$blocknews_new.url|escape}</h3>
<p>{$blocknews_new.$lang|escape}</p>
</div>
<div class="clear"> </div>
</div>
<p><img class="separator sep-line" src="1x1.png" alt="" /></p>
{/if}
   {/foreach}
<!-- /Block links module -->

 

and in the : blocknews/controllers/front/news.php

<?php
if (!defined('_PS_VERSION_'))
   exit;

Class blocknewsNewsModuleFrontController extends ModuleFrontController
{
public function initContent()
{
   parent::initContent();

   $news = $this->module->getLinks();

	    $this->context->smarty->assign(array(
			    'blocknews_news' => $news,
			    'title' => Configuration::get('PS_BLOCKNEWS_TITLE', $this->context->language->id),
			    'url' => Configuration::get('PS_BLOCKNEWS_URL'),
			    'lang' => 'text_'.$this->context->language->id
	    ));
	    if (!$news)
			    return false;
	    return $this->setTemplate('blocknews.tpl');
}
}

 

And i go to the link:

index.php?fc=module&module=blocknews&controller=news

 

And I CAN SE THE NEWS :) :)

 

Thanks so mutch.....

Link to comment
Share on other sites

  • 3 weeks later...

hello...

 

I´m wondering one thing.

 

if i whant to add truncate:320:'..... Read more' in the script.

and have a link from the read more to a page there the i can read the full text.

 

How can i do that, do you have a smart idé for that.

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...