Need some help with your project? Contact me

Cool module: Insert View

Insert View is a cool module that lets content creators insert an existing View right into their content. Using a simple syntax, users can specify which View should be rendered, with which Display and what arguments should be passed as contextual filters.

Think of the following use case. You have a View listing 3 node titles tagged with the same taxonomy term as the article that is rendered on the page. You want these titles appearing inside of the content but at different locations depending on where they fit best with the respective content. Using a simple syntax provided by this module, your editors can have this View rendered wherever they think it makes most sense. But let’s see how it works.

After you enable it like any other module, go to admin/config/content/formats and edit the text format you’d like this syntax to be parsed in. This should be the one your editors use for their content. You’ll see there a new checkbox you need to tick: Insert view filter. Now you’re good to go.

When you create new content using this text format, you can use the following syntax to insert a View: [view:name=display=args]. Three things basically: the machine name of your view (for example "my_view"), the display name of your view (for example "page") and optional arguments that will act as contextual filters (for example "arg1" ).

I’ll illustrate with an example. You have a Taxonomy Term Page View (you know that clone you make of the default taxonomy term display). This View has two Displays and you need to pass it a filter value (term ID) to show the content tagged with that term. So to include this View in your content using the syntax, you’d have to write: [view:taxonomy_term_pages=page=1], where "taxonomy_term_pages" is the name of your View, "page" is the display you’d like and "1" is the argument passed to the View (taxonomy term 1).

And it’s that simple. You can have any combination of the above too. You don’t need arguments if you don’t want to pass any - maybe the filter comes dynamically from the rendered node (see the use case above). Setting no Display will make the default View Display to be used. So it’s pretty flexible.

Hope this helps.


Thanks, danny!
You are the first one to point out that the view filter needs to be activated from the text format configuration.
I've been wrapping my head around this for the last 2 hours...

Add new comment

You can post comments in Markdown and basic HTML tags.
For code blocks, wrap your code within '~~~'. For example:
$var = 'my variable';