HowTo: Form Designer + Aparna = Custom Page Module with RSS feed

  • Overview

    Here the goal of this project is to create a new content type similar to the Page module and output to an RSS feed.

    The name of this project is going to be "Oilfield News". What we want to do is setup a new content type that will display on the main section of the site and is able to be added to by the site admin. It will also output as an RSS feed to whoever wants to read that feed.

    Lets get started.
  • Tools we're going to use

    For this project we are going to use the Aparna module to create a new base module to start on. We are going to use the Form Designer to add form fields.

    From there we're going to use the {jrCore_list ...} function to structure our list.

    and the Feed module to create our RSS feed
  • First, Create a new module

    Use the Aparna module to create a new module called "xxOilfieldNews".
    ACP -> TOOLS -> APARNA -> TOOLS -> CLONE -> New Module Name

    New Module Name: xxOilfieldNews
  • screenshot of aparna clone tool after the new module has been created
  • That will give us our new module found in the TOOLS section. (as all cloned module are initially found there.)

    Activate it and "Save Changes".
  • screenshot of the xxOilfieldNews activated
  • New Module Setup

    The Page module is found under the 'site' section so we'll change this module to there too.

    We also want a hyphen in the module URL, so we'll put that there now too.
  • screenshot of the INFO tab of the module just created
  • Activate the module for just the Admin's quota

    You can allow any users in any quota to create new items by checking the "Allowed on Profile" checkbox under the QUOTA CONFIG section of the module.

    For this module, we only want the admin user to be able to add items, so only check the checkbox for the quota that is reserved for admin users. On this system its called "Admin Quota" to remember easily.
  • You can read more about setting up quotas here:
    "The Quota System"
  • screenshot of the quota config tab on the new module
  • Get ready for the Form Designer

    To use the Form Designer, we first have to visit both the create and update forms for that content type.

    In order to get to the update form, there needs to be at least one item created. So create one item, then go to the update form.
  • screenshot of the create item button on the new module section of the admin profile
  • screenshot of the new item with a title
  • The result will look like this:
  • screenshot of new item on the profile.
  • Don't worry about how this section looks for now, we will be fixing it up to how we want it later.

    That display is controlled by the modules item_details.tpl file. Before we go customizing the layout of that, we first need to get the module ready to accept more information types.

    It needs at least an editable section to add the page content to. So lets do that next.
  • Adding an editor to the module

    We want to create the module similar to the Page module. The Page module has an editor to use, so we're going to put one into this module too.

    Click on the update (gear icon) to update the post we just added.

    In the update form, in the top right hand corner you will see a button with the text "Form Designer". Click that.
  • screenshot of the Form Designer button in the update form
  • The name of the field we want to add can be anything, but convention from the page module pushes us toward using the term 'body'.

    In the "New Field Name" section, enter oilfieldnews_body and click "Create New Field"
  • screenshot of the Form Designer create new field button
  • screenshot of the form to setup the newly created field for the update form
  • Change the Label, Help, Type, Required, and Active fields to what you desire.
  • screenshot of the same form filled in with desired values
  • The New Form

    Now that we have added an editor to the module, we can see the results of that when we use the update form.
  • screenshot of the editor showing up in the new module
  • Almost there, but we also want a date on the form too because its a news story.

    Any item created will store the date when it was _created and _updated but for news stories we want to be able to set the date independently so its back to the Form Designer to add a new field oilfieldnews_date.
  • screenshot of the Form Designer options form to add a new field
  • With those options in place in the Form Designer date field, our new form for the module looks like this:
  • screenshot of the modules update form with the new date field highlighted
  • Customizing the Display

    Now that we have the form we're after, we can add a piece of content to it and move on to dealing with the output page that we quickly looked at earlier.

    The first thing is to add some content to the item so we can see when it changes. For this item, my form looks like this:
  • screenshot of the new modules update form
  • But when I save it, I get taken back to the items details page and it still looks like this:
  • screenshot of the item_details page on the admins profile
  • Editing item_details.tpl

    The reason the image above doesn't look like we need it to look is because it needs to be customized to fit our module.

    This can either be done via FTP and altering the file
    /modules/xxOilfieldNews/templates/item_detail.tpl

    OR via the TEMPLATE tab in the ACP.

    The FTP method has been covered before here: "Creating a Module"

    So here we'll use the less programmer route and do it via the ACP.

    Go to:
    ACP -> SITE -> OILFIELD NEWS -> TEMPLATES -> item_detail.tpl -> MODIFY

    The field we added we gave the name 'oilfieldnews_body' so that information is stored with the rest of the item.

    When we want to get it output to the page, we put that variable where we want it to come out.

    Currently our item_detail.tpl page code looks like this:
  • screenshot of the MODIFY screen in the template editor
  • And the output of that code on the profile, looks like this:
  • screenshot of the item_detail code displayed on a profile
  • code

    We want to get rid of the pieces marked in red dotted lines, so we need to locate and remove them from the page code in item_detail.tpl.

    Thankfully what is currently being output to the page is all of the form fields contained in the item, so we can use them where we need them to get the desired output.

    After some re-arranging of the smarty code we come up with a layout that we want to test out.

    That new code looks like this:
    {jrCore_module_url module="xxOilfieldNews" assign="murl"}
    <div class="block">
    
        <div class="title">
            <div class="block_config">
                {jrCore_item_detail_buttons module="xxOilfieldNews" item=$item}
            </div>
            <h1>{$item.oilfieldnews_title}</h1>
    
            <div class="breadcrumbs">
                <a href="{$jamroom_url}/{$item.profile_url}/">{$item.profile_name}</a> &raquo;
                <a href="{$jamroom_url}/{$item.profile_url}/{$murl}">{jrCore_lang module="xxOilfieldNews" id="10" default="OilfieldNews"}</a> &raquo; {$_post._2|default:"OilfieldNews"}
            </div>
        </div>
    
        <div class="block_content">
    
            <div class="item">
                <div class="container">
                    <div class="row">
                        <div class="col12">
                            <div class="p5">
                                {$item.oilfieldnews_date|jrCore_format_time:false:"%B %e, %Y"}<br>
                                {$item.oilfieldnews_body|jrCore_format_string:$item.profile_quota_id}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            {jrCore_item_detail_features module="xxOilfieldNews" item=$item}
        </div>
    
    </div>
  • Activate the Template

    Save the changes, hit 'Cancel', then Activate the template.
  • screenshot of the checkbox to check to activate a custom template
  • The Result

    The Result
    screenshot of the resulting item_details page for our new module
  • Now the module exists, you can create lists in the same way any other module is listed.
    {jrCore_list module="xxOilfieldNews" ....}
  • The RSS Feed

    With the jrFeed module installed, your new modules RSS feed will be available at:
    your-site.com/feed/oilfield-news
  • Customizing the RSS feed

    You can customize the structure of the RSS feed by adding a file
    /modules/xxOilfieldNews/item_rss.tpl

    The base structure for this can be found in rss.tpl in the feeds module,
    /modules/jrFeed/templates/rss.tpl

    It looks like this
    <?xml version="1.0"?>
    <rss version="2.0">
        <channel>
            <title>{$rss_title}</title>
            <description>{$rss_desc}</description>
            <link>{$rss_url}</link>
            <lastBuildDate>{$rss_builddate}</lastBuildDate>
            {foreach $_items as $item}
                <item>
                    <title>{$item.title}</title>
                    <link>{$item.link}</link>
                    <description>{$item.description|jrCore_format_string:$item.profile_quota_id|strip_tags}</description>
                    <pubDate>{$item.pubdate}</pubDate>
                </item>
            {/foreach}
        </channel>
    </rss>
  • From there, you can use any field that your module has in the datastore.

    The $item.title in the code above is the generic fields looked for but because your RSS feed is specific to your module, you can use the module's prefixed actual datastore terms.

    $item.oilfieldnews_title
    $item.oilfieldnews_date
    $item.oilfieldnews_body
    etc...
  • So the finished code for the oilfield new item_rss.tpl file will look like this:
    <?xml version="1.0"?>
    <rss version="2.0">
        <channel>
            <title>{$rss_title}</title>
            <description>{$rss_desc}</description>
            <link>{$rss_url}</link>
            <lastBuildDate>{$rss_builddate}</lastBuildDate>
            {foreach $_items as $item}
                <item>
                    <title>{$item.oilfieldnews_title} wdd</title>
                    <link>{$jamroom_url}/{$item.profile_url}/{jrCore_module_url module="xxOilfieldNews"}/{$item._item_id}/{$item.oilfieldnews_title_url}</link>
                    <description>{$item.oilfieldnews_body|jrCore_format_string:$item.profile_quota_id|strip_tags}</description>
                    <pubDate>{$item.oilfieldnews_date|jrCore_format_time:false:"%a, %d %b %Y %T %Z"}</pubDate>
                </item>
            {/foreach}
        </channel>
    </rss>
derrickhand300
16 Feb 2015 03:29:05AM @derrickhand300:
Does that go the same for

$rss_title

would it be changed to

$rss_oilfieldnews_title

??Thanks for all your understanding :)

michael
16 Feb 2015 11:43:20AM @michael:
The $rss_title in the template is made by taking the prefix of the module and adding '_title' to it so whatever the module provides is still there. For your module, use the normal notation of {$item.oilfieldnews_title} inside the foreach loop.
derrickhand300
07 Apr 2015 08:36:23AM @derrickhand300:
Trying to create an rss feed to display my newest members from my members page here
http://drillingahead.com/members

The only url I can get a feed from is
http://drillingahead.com/feed/profile

But the feed is 100% empty- no content.

Thinking that I needed to edit the rss template I went to MODULES>USER PROFILE to look at the datastore and see what was available to add to the custom rss template- but there is no datastore located at MODULES>USER PROFILE

Any idea how I can get the member profile photos into a feed from the members page so I can output it using a feed reader?

Thanks!

Share This

Tags