# Dynamic Sections

Dynamic sections are components of a Tenant's site that function as sections but don't necessarily have dedicated tabs in their menus. They independently appear within the articles themselves and when accessed, are defined by some kind of tag.

Implementing dynamic sections for these types of pages reduces the amount of code that would otherwise be duplicated and prevents these sections from appearing in the lateral menu.

Dynamic sections commonly are used to include author sections and list all articles written by that author. For example:

www.example.com/authors/mike-kozik

Another example could be sites that have use tags to define dynamic sections.

www.example.es/tags/vegetarian%20recipes

# Create dynamic sections

  1. Insert the following code in the tenant's definition.json file for each dynamic section:




 


 
 




 

 


"sectionDefinitions" : [ {
    "name" : "author", --> the name of the section
    "title" : "author", --> the title of the section
    "feedDefinitions" : [ {
      "uri" : "/author/*", --> Ant path pattern that matches the dynamic url
      "alibabaDefinition" : {
        "configuration" : {
          "feedRipper" : "jsoupRipper",
          "jsoupSelectors" : "index/src/jsoup/author.properties"
        }
      }
    } ],
    "configuration" : {
      "titlePattern" : "/author/(.*)" --> Regex pattern to get the title of the section from the url
    },
    "type" : "DYNAMIC"
  }]

Ant Path Pattern

Ant Path Pattern (opens new window) is a directory based pattern

  1. Create a .properties files. The name in the filename should be the name of the dynamic section (for example, tag or author).

This file functions as a whitecollar: use it to define the selectors of the elements to extract.

The following is a usage example for the dynamic section showcased in the previous step above. The file example.com/index/src/jsoup/author.properties contains the following code:

ARTICLES=article, .article
TITLE=.title
URI=a
IMG=img
DATE=date
AUTHOR=.author
EXCERPT=.excerpt
SUBTITLE=.subtitle

As always, use a layout descriptor file to customize the layouts, naming it as the name of the dynamic section, in this case: author.s.json:

{
    "layouts": [
    "newspaper/pill",
        "newspaper/thumb"
    ]
}

Reminder

The layout descriptor filename must be equivalent to the section name as declared in definition.json.

# Dynamic Uri is a query parameter

If the dynamic part of the URI is a query parameter instead of part of the path, use the dynamicSectionAllowedQueryParams flag. Marfeel by default strips all the query parameters of the URL. It means that without this flag, /author?name=flore and /author?name=xavi lead to the same section page.

You can also extract the title from a query parameter. For example:





 








 
 




{
    "name" : "astuces_dyn",
    "title" : "Astuces",
    "feedDefinitions" : [ {
      "uri" : "/astuces/",
      "alibabaDefinition" : {
        "configuration" : {
          "feedRipper" : "jsoupRipper",
          "jsoupSelectors" : "index/src/jsoup/astuces.properties"
        }
      }
    } ],
    "configuration" : {
      "titlePattern" : "/(astuces)/(\\?)tag=(\\w+)",
      "dynamicSectionAllowedQueryParams" : "tag"
    },
    "type" : "DYNAMIC"
  }

Be mindful of the query parameter

Don't use this flag for any query parameter. If you plan to keep a parameter called page or p, if the value is a number, look out! You might be re-creating section pagination!

# Test dynamic sections in Local

Test a dynamic section in local like any other, with a URL following this format:

https://localhost.marfeelcache.com/hub/origin/<dynamicSectionUrl>?marfeeldev=true

# For example:
https://localhost.marfeelcache.com/hub/origin/www.example.com/tags/?marfeeldev=true

# Adding pagination

Jsoup ripper can retrieve the pagination links from the tenant's page. By default, Jsoup pagination works like all the other sections: it uses the selectors flag from the definition.json.

If the DOM items are different from other sections, you can declare them in the section's .properties file. Use those selectors:

PREV_SECTION_PAGE=.wp-pagenavi a[rel='prev']
NEXT_SECTION_PAGE=.wp-pagenavi a[rel='next']
CURRENT_SECTION_PAGE=.wp-pagenavi .current

TIP

Check the section pagination documentation to know if you need to configure the ripper, there are other ways to get a section's pages.