News module import to the CMS pages
Hi All,
I've built a news module base on the tutorial http://docs.getfuelcms.com/general/pages-variables#news
.
And now, I would like to import the news view file into the my CMS pages but it said it cannot be upload.
May i seek your advice that what should I do? Or any recommendation for me that I also built a Carousel slideshow module and it's view file will be show in the same page above the news.
Many thanks.
Comments
{fuel_block('slideshow')}<?code> In addition, if you are wanting to add custom parameters to the block, then I'd recommend something like a block layout which you can customize on a per page basis (think of it as a nested set of layout fields for a page): http://docs.getfuelcms.com/general/layouts#layouts_block_layouts
Many thanks and it's what I am looking for.
But I fact another question, I get 404 error when I click slug linking or readmore even my coding is same as the tutorial.
I try to call the news_item but there's no data. Is my setting something wrong?
Thanks a lot.
Here is my module (news_module) which under "\fuel\application\models"
<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once(FUEL_PATH.'models/base_module_model.php'); class News_model extends Base_module_model { public $required = array('headline'); public $record_class = 'News_item'; public $parsed_fields = array('content'); function __construct() { parent::__construct('news'); } function list_items($limit = NULL, $offset = NULL, $col = 'release_date', $order = 'desc') { $this->db->select('id, headline, slug, language, release_date, published'); $data = parent::list_items($limit, $offset, $col, $order); return $data; } function on_before_clean($values) { if (empty($values['slug'])) $values['slug'] = url_title($values['headline'], 'dash', TRUE); if (!intval($values['release_date'])) $values['release_date'] = datetime_now(); return $values; } function form_fields($values = array()) { $fields = parent::form_fields(); $fields['slug']['comment'] = 'If no slug is provided, one will be provided for you'; $fields['release_date']['comment'] = 'A release date will automatically be created for you of the current date if left blank'; return $fields; } function _common_query() { parent::_common_query(); // to do active and published $this->db->order_by('release_date desc'); } } class News_item_model extends Base_module_record { protected $_date_format = 'F d, Y'; function get_url() { if (!empty($this->link)) return $this->link; return site_url('news/'.$this->slug); } function get_excerpt_formatted($char_limit = NULL, $readmore = '') { $this->_CI->load->helper('typography'); $this->_CI->load->helper('text'); $excerpt = $this->content; if (!empty($char_limit)) { // must strip tags to get accruate character count $excerpt = strip_tags($excerpt); $excerpt = character_limiter($excerpt, $char_limit); } $excerpt = auto_typography($excerpt); $excerpt = $this->_parse($excerpt); if (!empty($readmore)) { $excerpt .= ' '.anchor($this->get_url(), $readmore, 'class="readmore"'); } return $excerpt; } } ?>
Here is my view file (news.php) under "\fuel\application\views\_blocks"
<?php $slug = uri_segment(2); if (!empty($slug)) { $news_item = fuel_model('news', array('find' => 'one', 'where' => array('slug' => $slug))); if (empty($news_item)) show_404(); } else { $news = fuel_model('news', array('limit' => 2, 'where' => array ('language' => $language), 'order' => 'release_date desc')); } ?> <?php if (!empty($news_item)) : ?> <?php fuel_set_var('page_title', $news_item->headline); ?> <blockquote class="blockquote-red news_item"> <h4 class="heading-red"><?=$news_item->headline?></h4> <p><i class="glyphicon glyphicon-calendar"></i> <?=$news_item->release_date_formatted?></p> <p><?=$news_item->content_formatted?></p> </blockquote> <?php else: ?> <?php foreach($news as $item) : ?> <blockquote class="blockquote-red"> <i class="glyphicon glyphicon-calendar"></i> <?=$item->release_date_formatted?> <?=$item->get_excerpt_formatted(200, 'Read more »')?> </blockquote> <?php endforeach; ?> <?php endif; ?>
Here is my MY_fuel_modules.php setting:
/*********************** OVERWRITES ************************************/ $config['module_overwrites']['categories']['hidden'] = TRUE; // change to FALSE if you want to use the generic categories module $config['module_overwrites']['tags']['hidden'] = TRUE; // change to FALSE if you want to use the generic tags module /*********************** /OVERWRITES ************************************/ $config['modules']['news'] = array( 'preview_path' => 'news/{slug}' );
http://docs.getfuelcms.com/general/pages-variables#specifying_a_view
And sorry for my careless that I missed to study the last part of the tutorial.