jade / express - when to use or not to use layouts - layout

I've just started developing in express and am new to Jade as well.
I'm having trouble deciding when it's appropriate to use layouts and when not to. I'm also having trouble deciding when it's appropriate to use something like blocks vs. partials.
Any help regarding this is truly appreciated. I'm a little lost.

It's mostly a matter of preference. If you are used to something like Wordpress where you have a concept of a header and footer that you include into pages than you might not like layouts. I personally only use layouts with content blocks because the non-layout way tends to cause more repetition.
As for partials vs blocks. You use a partial for items that you want to reuse on different pages. While a block is a chunk of html that will be replaced by child templates.
An example of a partial can be the html for a product. So you have a thumbnail, the title and a description of a product. You might use this partial while listing the products in a category. But you might also use this partial for rendering a list of search results.
An example of a partial can be a main layout that contains you header and your navigation and a content area. If you want to reuse this main layout on multiple pages you will extend this it and overwrite the block in the child templates.

Related

How to set up a global CSS for an entire page in Liferay DXP?

I am new to Liferay, and I still don't know the difference between the various 'kind' of Liferays.
This Liferay is what I am talking about.
I understand that you have to create a page first, and then add components (fragments) in it.
I also understand that you can go to fragments, and create a custom fragment with a custom CSS, and then import it into your page.
However, what I want to do is have a global CSS that I can use for all fragments inside a page, rather than having to add CSS for each fragment.
Is that possible, and if so, how?
I know I can use the 'style-books' which apply to an entire page, however, I don't know how to customize them, and it doesn't seem that that's even possible.
To avoid coding, you can use the css additional textbox provide by theme settings.
It's a whole page css addon for every pages in the site

Custom rendering of a taxonomy - without using HTML lists

I have a multi-layer taxonomy that I want to display in a Bootstrap 'row/column' layout. How do I stop Orchard from rendering it as an HTML list?
At present I am having to create alternates at quite a high level. So far:
1. Parts.TaxonomyPart-url-MyTaxonomy
2. TaxonomyItem-MyTaxonomy
3. TaxonomyItemLink-MyTaxonomy
The first is required to remove the main <ul> that is automatically added by Orchard.
The second removes the <ul> from any child terms
The third handles the display of the actual taxonomy term (my custom HTML).
It works, but I'm sure there's a less cluttered way of doing it that I can't see.
I would prefer to alter the rendering of the taxonomy this way rather than create a projection, as I find projections don't handle taxonomies with hierarchies very well / easily.
Any help / suggestions would be much appreciated! Comment if you need more info.

Inserting a news-feed widget to a page

I have a page I'd like to embed a news-feed widget into (so that the feed from some remote site will be displayed in my site).
While there are quite a few free news-feed widgets available out there (a partial list is here: http://allwebco-templates.com/support/S_script_newsfeed.htm), They all require insertion of complex code into the html page, while all the parameters are hard-coded into the generated code, which looks something like this:
insertedWidgetText = "<script id=\"scrnewsblock10795953\" type=\"text/javascript\">...script specific parameters go here...</script>"
let feedWidget = toWidgetBody [hamlet|#{preEscapedText insertedWidgetText}|]
This doesn't integrate well with Yesod's approach as it requires specifying to Hamlet that the content is preEscapedText, which in turn disables the ability to use Hamlet's processing to alter parameters of the widget dynamically (So in case I want the widget to use a different source, for example, I need to statically change the quoted text and cannot use Hamlet's variable substitution).
Of course I could do some text manipulation myself, tailor built for the widget I'm using, but that doesn't seem like the "right" solution (especially if I want to have the embedded text in some external file and not in the middle of my code as in the example above).
Can the above mentioned issue have a better solution than the one I thought about?
Is there an implementation of a news-feed widget in Haskell/Yesod that I can use as a plugin?
Note: I'm a very poor javascript programmer, but solutions in that direction are also welcomed.
Thanks,

How to provide the current route or view to the layout in ExpressJS?

I want to be able to dynamically reference JavaScript and Stylesheets depending on which page a user is on in Express. I thinking the best way to do so (though I'm open to suggestions) is to pass the current view to the layout page.
For example;
Given the url http://example.com/trees
I would want to have some logic in layout.jade that said something to the effect of:
script(src="/javascripts/{view}.js")
Which would get rendered as:
<script src="/javascripts/trees.js"></script>
Any suggestions or best practices for doing this?
req.route is the matched route, so things like req.route.path etc are available, or of course req.url which may be parsed. With express 2x you can expose these values to views automatically using "dynamic helpers" or res.local()
There are no best practices for doing this, since Express doesn't provide Rails like url helpers, so I think you're approach is fine.
The easy answer is to just put ALL your javascript into a single file and be done with it. Ditto for CSS. See the Ruby on Rails asset pipeline for details. You are probably making your life more complicated than necessary and also less efficient by having different javascripts on different pages.
However, since you asked, the answer for javascripts is easy. Just put the extra <script> tags in the view, not the layout. Problem solved. CSS doesn't work as cleanly because the <link> tags need to be inside the <head>. In this case, I define the styles I need as an array of strings and loop over that in my layout template. So in my route I set up a local variable such as
locals.css = ['/css/one.css', '/css/two.css']
Then just loop over that in your template and generate one <link> tag for each.

Overriding Core Shapes - Orchard CMS

I currently have a Content Type called "News" which is very simple (No custom properties etc.). I am trying to style this Content type when it occurs on a page of a specific layout, in this case a "News" page.
So - I have the layout that a News page will inherit from (Layout-url-News.cshtml), however I cannot seem to get the Content to display or inherit from a template (I have tried creating alternates such as Zone-url-News.cshtml and Zone-Content-url-News.cshtml, however both result in having no content at all.)
I had create both of the mentioned alternates by hand, as Designer Tools was unable to generate an alternate (The relative virtual path 'Orchard.Core.Shapes.CoreShapes::Zone' is not allowed here)
Basically - I cannot figure out how to style the content found on a specific page, (Title, Tags, Date, Body) as the Content always seems to inheirit from the base shape.
If your point is to style content in a zone, u might find it easier to use css. The layout system makes it really easy to identify the elements your interested in styling by using css selectors.
for example
.aside1.news { ... }
That takes care of 80% of styling needs
Most of the remaining is taken care of by the placement.info file which allows you to indicate which fields and what order for contenttypes and viewstypes (summary and detail)
the remaining needs are address by overriding the contentitem.view.
But you seem to indicate that you want to set the style for a contenttype in a specific zone for a url. So... You have the same contentType in different zones at the same url? I cannot imagine what you are doing. :)
Long and short, it sounds like your focused on the zone but it might be more helpful to focus on the contenttype or better yet, css. I ran into the same thing with url alternates suggesting alternates that aren't valid. It seems weird that it suggests zone alternates. I don't think those those are allowed.

Resources