Mixing two modules Articles(new) and Pages

edited April 2017 in Modules
Hello,

as far as I'm a totally new user of FUEL, some issues are still a big challange for me. How do you think guys - is it possible to write a new module - Articles where I could add new publications with attachments, relate them with a page AND THAN mix it with Pages modul so I could make relation between article_id and page_id? In front-end the page would display (except of its own content) a list o related articles. I want to try this but let me know if it's possible. And second thing - can I set every new page will have a body_class = page_id? Thanks in advance!

Comments

  • There's two ways, the hard way - as you describe - where you would need to overload the pages module with your own code, or the easy way where you acquire the page identifier, run a $module->find_all() to get the articles and display them - do that inside the ./views/_layouts/main.php. You could build a helper to make it easier.
  • edited 4:48PM
    @almostcompletely thx! And it has to work both ways - when I want to publish new article, I need to list all available pages and assign the art to some page... If someone has more advices please drop a line!
  • edited 4:48PM
    If you create an Articles module, you can use a the "multi" field in your Page layout and use the "model" parameter to populate the select field with the articles you want to associate with it. Below is an example if you used a Custom layout class:
    http://docs.getfuelcms.com/general/layouts#layouts_custom_classes
    function fields() { $fields = parent::fields(); // PUT YOUR FIELDS HERE... $fields['articles'] = array('type' => 'multi', 'model' => 'Articles_model'); return $fields; }
    This would save the IDs of the related articles in for that page and then you could do something like the following in your layout and/or view file:
    $articles = fuel_model('articles', 'within', array($articles)); foreach($articles as $article) : echo $article->title; endforeach;
  • edited 4:48PM
    @admin that was very helpful - thank you! So let's get down to work:)
Sign In or Register to comment.