How to modify a pyramid template on the fly before rendering - python-2.7

please I am working on a site where I would scrap another website's html table source code and append it to my template before rendering my page.
I have written the script which stores the html code in a variable but don't know how to appendix it.
Kindly suggest.

If you're using jinja, try this:
<div class="html-content">{{scraped_html|safe}}</div>

Here is the code for the chameleon template system. HTML is the variable that contains your html code that is passed to the template.
<div>${structure: HTML}</div>
Or I believe this will work also
<div tal:content="HTML"></div>

Related

How can I include a template in another with pandoc?

I am using Markdown files to create a series of webpages (calling that mess a website would probably be frowned upon). I use a general template to display each page with a similar look: they all have the same header, footer, etc.
I would like to add a navigation menu, in order to have links to the other pages. I can easily generate the menu itself, what I don't know is how to insert it in the page.
What I tried is the following:
options.yml (generated by a Python script):
metadata:
title: My very excellent title
navigation: HomeOther page
standalone: true
template: template.html
template.html:
<!doctype HTML>
<title>$title$</title>
<header>Yeepee, header!</header>
<nav>$navigation$</nav>
<main>$body$</main>
<footer>Best footah evah</footer>
I then run the script: pandoc -d options.yml index.md -o index.html (and same for the other files, in a loop in a Python script)
The result is that the content of my metadata.navigation is escaped before insertion, resulting in something like <a href="index.html">Home</a><a href="other.html">Other page</a>, which is really safe in practice, but doesn't help me there.
What I would like is to have another template, say navigation.html, that contains the navigation menu to be included in my main template when using pandoc.
If this is not possible, I would like to use the same technique as above, but with an "unescaped" navigation parameter (I'm not fond of it, as it would bring a major security issue into the project).
How can I achieve this?
There are two solutions to this:
Use variables instead of metadata in your defaults file. Variables are inserted verbatim, while metadata will be escaped.
To insert the file navigation.html in a template, use ${navigation.html()}. Pandoc uses the doctemplates package for templates, see the docs on "partials" for more details.

Cannot display post of Blogger with custom template code

I make this code:
<b:widget id='Blog1' type='Blog' locked='true'>
<b:includable id='wrap' var='post'>
<b:loop var='post' values='data:posts'>
<b:include name='post' data='post'/>
</b:loop>
</b:includable>
<b:includable id='post' var='post'>
<a expr:href='data:post.url'><h3><data:post.title/></h3></a>
<p><data:post.author/></p>
<section><data:post.body/></section>
</b:includable>
</b:widget>
Here is the problem, it cannot display the post which is title, author name, body. I don't understand why, I've done everything like the "Help page" of Blogger said but it is not working. I also try to use original code of old template (which still working well) but it just have a same fate with my code when I paste it into my new template, not working.
Does anyone have any idea?
I have a similar problem.
This happens because in a recent update Blogger automatically saves post.body elements in a specific order and does not let you to alter it.
Still trying to find a workaround myself.

Taking all javascript from html to page-specific js file

What bit bothers me about django, is that I see in many examples that raw javascript is included in html with <script> tag. I would like to have it in independent files which are included in every page in <head> tag so that html stays clean. So that I will call something like {% add_jscript %}some js code{% endaddjsscript %} anywhere in the template to add js code. After all processing when the page is generated and it will dynamically collects all portions of added js code from processed templates and serve it as one js file.
Some app already does this or am I forced to do this on my own ?
I use django-sekizai (https://github.com/ojii/django-sekizai/) for this kind of thing. If I understand you correctly, I believe that is what you are looking for.
I know I'm a bit late to the party, but another option you could try (shameless plug) is a django app i've been working on which will allow you to inject django variables directly into external javascript files, a la Require.js
django-js-variable-injector

RenderComponentPresentation before any other markup Tridion Razor Page

I have a page template in Tridion 2011 with Razor code that prints information based on RenderComponentPresentation() as the first thing in the page. No other markup comes before it, because the component, not the page, contains the initial markup. Unless I put at least one character before the first RenderComponentPresentation in the published output, the template refuses to render any presentations.
So, for example, if this is all that is in the layout TBB this works (in my real code the tcms are real of course):
<
#RenderComponentPresentation("tcm:mytcm","tcm:myothertcm")
but this does not
#RenderComponentPresentation("tcm:mytcm","tcm:myothertcm")
The first prints the contents of the component preceded by the "<", whereas the second does nothing at all. I don't want to have ANY markup directly at the start of the page template, I want the first thing to be the component. Is it possible?
I've just done a quick test in Template Builder using the latest version of the Razor Mediator (1.2) and couldn't replicate your issue.
Maybe you could try:
<text></text>
#RenderComponentPresentation("tcm:mytcm","tcm"myothertcm")
It won't render any additional markup but may trick the mediator into doing what you want (though like I said, I can't replicate your problem so can't verify whether it does).
Normally with Razor you iterate over any and all Component Presentations on the page, and right now I'm working with
#foreach(var cp in ComponentPresentations){
#cp.RenderComponentPresentation()
}
This will render every component on the page, regardless of predefined schema's or templates. Your issue however suggest a problem elsewhere. What kind of output does your page template generate (do mind its the page template using a compound template which in turn includes the Razor TBB you describe here). Is it .aspx, HTML or other? And what is the Component templates' output? is it an HTML fragment, or anything else?
As far as you syntax goes, that should be just fine other than the template invocation:
#RenderComponentPresentation("tcm:x-xxx-xx", "tcm:xx-xxx-xx")
I have a feeling this code only works when used within HTML tags, though, but that's just a hunch.
Bit of a hack but have you tried:
<text>#RenderComponentPresentation("tcm:x-xxx-xx", "tcm:xx-xxx-xx")</text>
or
#Html.Raw(RenderComponentPresentation("tcm:x-xxx-xx", "tcm:xx-xxx-xx"))
Disclaimer: not really used Razor mediator. Just Razor.

modx is only showing html code, not the template

I have installed ModX and Downloaded the "Basic" Template in the Extensionmanager! I chose the Basic Template at my first Page for the Resource! I cant find a Globalsetting to choose an Template? My problem is that if iam going to the site i only get the pure html code shown, no website! Why is this?
AFAIK there is no "Globalsetting" to choose a template. One of the nice things with MODX is that each resource can specify which template to use. So you can mix and match as required.
You could check if you have set the base href tag in head like this:
<base href="http://www.yoursite.com"/>
It will tell the site where to start looking for the other files that you have included in your markup.