Is there a way to get </onlyinclude> included onto a MediaWiki page via a template? - templates

I want to add action points to a page via a template. This requires that the page with the action points contains this code:
<onlyinclude><includeonly>
</includeonly>#AP1 blah</onlyinclude> ... blah blah blah <onlyinclude><includeonly>
</includeonly>#AP2 blah</onlyinclude>... blah
But I want this via a template, so that a user only has to add something like:
{{subst:Action point|<action>}}
using the template: {{Action point}}.
The problem is adding the </onlyinclude> to a page. I can add <onlyinclude> using:
`<onlyinclude><onlyinclude></onlyinclude>`
I've tried adding hidden comments, using <noinclude> and <includeonly> but nothing seems to work.
Any ideas? The solution I'm looking for is where (as the above link explains) I can add text (meeting minutes) with action points on one page, and on another view only the action points.

This is a monstrous hack, but it works. You will need a recent version of MediaWiki that supports safesubst:.
Create the page Template:Startinclude with the content <onlyinclude><onlyinclude></onlyinclude>.
Create the page Template:Endinclude with the content </onlyinclude>.
Create the page Template:Ap with this content:
Head
<includeonly>{{safesubst:Startinclude}}</includeonly>
Body
<includeonly>{{safesubst:Endinclude}}</includeonly>
Foot
And now {{subst:Ap}} expands to this:
Head
<onlyinclude>
Body
</onlyinclude>
Foot
For a live demo, enter {{subst:User:Jpatokal/Ap}} on any Wikipedia page, it uses this template.

Wouldn't <onlyinclude> and </onlyinclude> work just as well as <onlyinclude><onlyinclude></onlyinclude> and </only<noinclude></noinclude>include>?

You could apply the following trick, within the template in order to transclude and substitute <onlyinclude> or <noinclude>:
<{{{fwd|onlyinclude}}}>Some text...</{{{fwd|onlyinclude}}}>
Some text...
<{{{fwd|noinclude}}}>Some text...</{{{fwd|noinclude}}}>
After the substitution the {{{fwd|}}} variable will be expanded at its place with the default value and you will get the desired tags. I'm using fwd as shortcut of forward, but you could choice different name.
Here is how to insert a category in to a page by template substitution using this approach - the template content should be:
<{{{fwd|noinclude}}}><includeonly>[[Category:CatName|?]]</includeonly></{{{fwd|noinclude}}}>

Related

OrchardCMS Replacement Tokens for Query Results displaying HTML tags instead rendering them

I am having problems understanding the token system for the output of query / projections.
If I leave the property as is it displays the text content with HTML formatting intact.
But I need to wrap it with a tag, the html tags get displayed as text.
Rewrite Results -> Rewrite output
<div class="collapse" id="toggle_{Content.Id}">
{Content.Fields.CaseStudy.ClientChallenge} </div>
I am trying to create a collapsible text area, I already have a button that hides/unhides the content.
Why is it displaying as text instead of rendering the tags properly.
I think this is because I don't know how replacement tokens work.
Another example problem is up one level on the edit Layout, I want to set the item class to work-item {Category}, Category being the name/title of a property, which I am using for grouping.
Right above the projection: I want to include some html that lists all the Categorys in a ul i.e. data-filter=".experiential" I have tried things like: work-item {Category} and work-item {Content.Fields.CaseStudy.Category}. Category is a "term" (?) from a taxonomy.
I feel like I am failing to understand how it all works.
Submitted as a bug https://github.com/OrchardCMS/Orchard/issues/7355
Will edit and post if it is fixed. In case anoyong else comes across this issue.

New Line on Django admin Text Field

I am trying to create a blog o django where the admin posts blogs from the admin site.
I have given a TextField for the content and now want to give a new line.
I have tried using \n but it doesn't help. The output on the main html page is still the same with \n printing in it. I have also tried the tag and allowed tags=True in my models file. Still the same. All the tags are coming as it is on the html page.
My Django admin form submitted:
The result displayed in my public template:
You should use the template filter linebreaks, that will convert the reals \n (that means the newline in the textarea, not the ones you typed using \ then n) into <br />:
{{ post.content|linebreaks }}
Alternatively, you can use linebreaksbr if you don't want to have the surrounding <p> block of course.
After searching the internet and trying different Django Template Filters, I came across one specific filter, SAFE.
For me, LINEBREAKS filter didn't work, as provided by #Maxime above, but safe did.
Use it like this in your html template file.
{{post.content|safe}}
To have a better understanding of SAFE filter, i suggest reading the documentation.
{{post.content|linebreaks}}
This will make the line in the textbox appear as it is without using \n or \.
{{post.content|linebreaksbr}}
Besides the newline function in your CSS Declaration will work too.

Add list view to Fluid template

I've built a custom extension which displays comments for a page.
But, of course, I want to have the comments section on every page. Is there a way to add it into the Fluid template so that I won't have to add it to every single page?
Looking for something like this:
<f:blabla.bla extension="tx_comment" action="list"/>
You don't need to create your own viewhelper for this. You can use the VHS extension and use render.request
<v:render.request action="[string|NULL]" controller="[string|NULL]" extensionName="[string|NULL]" pluginName="[string|NULL]" vendorName="[string|NULL]" arguments="{foo: 'bar'}" onError="NULL" graceful="1">
<!-- tag content - may be ignored! -->
</v:render.request>
https://fluidtypo3.org/viewhelpers/vhs/master/Render/RequestViewHelper.html

Orchard CMS: Creating bookmark for List item

We're creating a page in Orchard CMS using the 'List' Content Type. We want to add some hyperlinks at the top of the list, that will jump down the page to specific items in the list.
We specifically don't want to just link to the individual page for the list item, but jump down to where it is in the list, and because the list items are rendered using the same View part, we can't of course just hard code the bookmarks.
We've been customising the View Part in VS and know that the list item title is generated using the code:
#Display(Model.Header)
And this generates < h1 > and < a > tags to wrap around the title like this:
< h1 shape-id="5" >< a href="/Orchard/Contents/Item/Display/36" shape-id="5" >Marketing< /a >< /h1 >
However, we can't find a way to get the Display() method to include a 'name=' clause which we can then use as the bookmark.
We've also tried adding a new tag just above the exiting code, e.g.:
< a name="#Model.Header" >< /a >
#Display(Model.Header)
But of course the Model.Header is an object reference, and not some text, so this failed. After this we've got lost with various ways trying to find a property of the Model object to fetch the Title as text but couldn't.
There must be a way to overload the Display() method to get it to include the 'name=' clause, anyone got any ideas?
Model.Header is just a zone. What really renders the title is a shape that was added to that zone. You should really use Shape Tracing (part of the Designer Tools module) to understand what the hierarchy of shapes looks like. You don't need to "overload the display method". What you need is to override the template for the shape that is rendering the title (which is not Model.Header but something inside it).
You might want to read this: http://weblogs.asp.net/bleroy/archive/2011/03/27/taking-over-list-rendering-in-orchard.aspx and this http://weblogs.asp.net/bleroy/archive/2011/05/23/orchard-list-customization-first-item-template.aspx
Try:
<a name="#Model.Header.Items[0].Title" />
It's not pretty, but it worked for me when I dropped this in an alternate template for a biography content type I created (Views/Content-Bio.Summary.cshtml).
Based on Bertrand's suggestion, instead you can try:
<a name="#Model.Title" />
in your template alternate.

Django: How do I prepend

I'm exploring Django and got this particular problem.
How do I prepend <span class="label">Note:</span> inside {{article.content_html|safe}}?
The content of {{article.content_html|safe}} are paragraph blocks, and I just wanna add <span class="label">Note:</span> in the very first paragraph.
Thanks!
Sounds like you want to write a custom tag that uses BeautifulSoup to parse the HTML and inject the fragment.
There's no easy way. You can easily prepend to all articles.
<span class="label">Note:</span>
{{article.content_html|safe}}
If that doesn't help you consider changing the structure of article.content_html so you can manipulate with blocks from django templates, so it should look something like this
{{article.content_header}}
<span class="label">Note:</span>
{{article.content_html}}
If that solution is not feasible to you and you absolutely need to parse and modify the content of article.content_html, write your own custom filter that does that. You can find documentation about writing custom filters here http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#writing-custom-template-filters.
An alternate approach could be to do this with javascript. In jQuery, it would look something like:
var first_p_text = $("p:first").text()
$("p:first").html("<span class="label">Note:</span>" + first_p_text)
Note though that if there are other elements inside your first p, $("p:first").text() will grab the text from those as well - see http://api.jquery.com/text/
Of course, this relies on decent javascript support in the client.
jQuery is the simplest and easiest to implement. You only need one line with the prepend call (documentation):
$('p:first').prepend('<span class="label">Note:</span>');
Explanation: 'p:first' is a jQuery selector similar to the ':first-child' CSS selector. It will select the first paragraph and the prepend call will then insert the span into that selected paragraph.
Note: If there is a paragraph on the page before your content, you may have to surround it with a div:
<div id='ilovesmybbq'>{{article.content_html|safe}}</div>
Then the jQuery call would be:
$('#ilovesmybbq p:first').prepend('<span class="label">Note:</span>');