Hugo change layout - hugo

I have a following structure in my Hugo & Doks project:
- content
- docs
- working.md
- working-as-well.md
- get-started2
- working.md
...
- get-started.md
...
- layouts
- get-started2
- single.html
- get-started.html
Content placed in docs and get-started2 has customized layout and works as expected. Great!
However, I have huge pain to set-up custom layout for get-started.md. I cannot do it like with get-started2 - place it into a folder. Client requests to have get started URL as:
www.SomeProject.com/get-started
so it must not be placed in folder (like get-started2)
www.SomeProject.com/get-started2/working
Do you have any hints please?

You have at least three options:
Use front matter to set the "type":
In content/get-started.md set type: mytype in front matter.
The layout will be located at (for example) layout/mytype/single.html.
Use front matter to set the "layout":
In content/get-started.md set layout: mylayout in front matter.
The layout will be located at (for example) layout/_default/mylayout.html
Or use a subdirectory, but make it the section index:
The file is located at content/get-started/_index.md
The layout will be located at (for example) layout/get-started/list.html
Notice that the template name has changed from "single" to "list", but you can still write your layout in exactly the same way.
I use "(for example)" because Hugo has an enormous list of directories/filenames it searches through to find its templates, and if an earlier matching template is found, the custom layout gets ignored.

Related

How to use the same layout in a different directory?

I have a site using the hugo-coder theme, which has a layouts/posts folder that specifies that anything in the "posts" folder will have a blog post format.
I would like to have two different blogs in two different subdirectories, using the same layout. Is there a way to tell Hugo that the content/blog1 directory should use the same settings and layout as the content/posts directory without copying themes/hugo-coder/layouts/posts into layouts/blog1? Ideally I would avoid using symlinks, because, while convenient, I've had a decent amount of software throw weird errors when I use symlinks, so I avoid them when it's possible.
You can set the layout or type field to posts in the frontmatter of your _index.md file in content/blog1.
See this docs page for more info.
Edit: Alternatively, you could create an archetype for blog1 that automatically sets the value to posts in the frontmatter of individual posts in that section, assuming you're using hugo new blog1/postname.md to create posts for that section.
Double edit: The first suggestion didn't work. You could also create subsections within content/posts/blog1 and set the permalinks of posts in that subsection to use the last section only. That should remove the need to explicitly set the type in post frontmatter every time because each post would already have a type of posts.
In config.toml:
[permalinks]
posts = "/:sections[last]/:slug/"
You can use a partial in your templates. If you do that you WILL need the single and list file in the layouts/blog directory, but it could be an empty file referencing the partial. The layouts/posts/single.html and the layouts/blog/single.html both will then look like this:
{{ partial "singleblog.html" . }}
Compeletely DRY... and without much complexity.

Share front matter between translations

I have a Hugo site with translations per file, using page bundles.
So the About page looks like this:
- about
- about-image.jpg
- index.en.md
- index.nl.md
- index.fr.md
The problem is that I have to repeat the non-i18n front matter in all of the .md files.
For example, date, tags, et cetera.
Is there a way in hugo to define the (basic) front matter once, and have translations only contain overrides needed for i18n?
You can define the default language in the config file of the site.
Then, you set the strings that do not need to be translated only into the translation file of the default language, and you do not define them in the other files.
As the translations are missing, Hugo will default to the default language (if defined in the config file).
https://gohugo.io/content-management/multilingual/#missing-translations
Hugo now brings with it front-matter cascade param which you can use to make descendant pages or even translation pages like
cascade:
- _target:
kind: page
lang: en
path: /blog/**
background: yosemite.jpg
- _target:
kind: section
background: goldenbridge.jpg
title: Blog
Learn more here https://gohugo.io/content-management/front-matter#front-matter-cascade

Create Landing Page in Drupal 7

In Drupal one can basically style the elements, like the search box, or the basic page etc. and then put some content in the site and the resulting page will be generated. But what if you want one specific site (e.g. the index page) to be different? E.g. have a image as a background, a different navigation styling etc.
What's the best paractice way of doing this?
Best practice is to have a different theme which you can switch to by using hook_custom_theme() where you check the current path. Also make sure that your theme to switch to is enabled:
/**
* Implements hook_custom_theme().
*/
function YOUR_MODULE_custom_theme() {
# check path with arg(0)
# return theme name to switch to
return 'different_theme_machine_name';
}
Alternatively you can also try ThemeKey doing this out of the box with an interface & allowing you the specify rules.
If you need to change only the content(body) section of your page, use Disply Suite. You can create unique look and feel layouts for your body section of each page.
If you trying to change the complete layout of one page (eg: Services), Create new Content Type 'Services'. Then create a template file for this content type, You must name this template call page--services.tpl.php. And also you can overwrite the index page layout by creating page--front.tpl.php template. Done!
What you are saying you want to change is all styling. And you know you can do a page to look drastically different with CSS... and you can do it that way depending on your chosen Drupal theme.
Now, with the Chrome Inspector (or FF inspector) look at the body tag, it probably has many classes which indicates in what page you are, what type of node (if it's a node) or if it's an admin section, or an anonymous user.
Using those specific classes you can style a frontpage, or a view, or a node, or anything, without installing more modules... with some limitations because you can't change rendered HTML this way.
Finally, don't get scared by using modules in Drupal, it's how Drupal works and it works pretty well. The thing is to install the best tools to increase your productivity, and Drupal have excellent options to change your theming and content like Display Suite (like #BaikHo suggested).
Hope that helps.
PD: Using the less module and with custom your theme you can have LESS css which is considerably faster than using only CSS, and because it's integrated with Drupal you can theme make everything even faster. Give it a try.

Drupal 7 - Blocks: how do you specify it a list of pages except certain pages?

I created a block that I want to appear on these paths:
example.com/sample/1
example.com/sample/2 example.com/sample/3
example.com/sample/4 example.com/sample/6
However, I don't want it to appear on:
example.com/sample/5
Under the visibility setting for the block, I can select show block on "Only the listed pages"
and enter something like /sample/*
Howevever, how do I tell it not to show up in /sample/5 without typing out all other paths individually? Is there an "except" or "not" indicator somehow like how the * indicates all?
Use the context module to handle the placement of your block. It allows you to specify which paths the block should display on, as well as which it should not (by starting the path with a ~)
For example, in your context you can specify your paths like so:
sample/*
~sample/5
this tells drupal to display your block on all paths that match "sample/*" except for "sample/5"
There is only two ways of getting the fine tuning you need:
You type one by one all the URLs you want to include/exclude
You go for the perfectly customizable php code mode.
Maybe you should try Context module http://drupal.org/project/context and see if the more complex, configurable options it provide serve your purpose/solve your problem.
PD. My first answer completely missed the point, i was thinking on views... sorry!

How to alter the prefixes EPiServer is adding to src attributes in html

I have a fragment of html which is contained in a property of a templated EPiServer page, within that html there is an img tag which has a relative url in it.
When the page is viewed, I can see the src attribute of the tag has been altered to have the prefix /ProjectName/Templates/Pages/.
I understand that this is being done by HtmlRewriteToExternal so that image files that are stored alongside the aspx template (which does indeed live in Templates\Pages) are located correctly, however the image which is intended to be part of the html fragment is in my case actually stored under PageFiles/nnn/ (where nnn is actually the parent page's PageFolderID), and I need to somehow make the altered html reflect that.
I've created a class that inherits from FriendlyUrlRewriteProvider and registered my class. I can debug the application, and watch the requests go through the overridden methods, but I still can't see where the prefix is being added or get any idea how to change it. I can alter the src tag to a different relative path in my class, but the prefix is still being added.
I've read everything I can find on the EPiServer url rewriting, but can't find anything that hints as to where this prefix is being added or how to stop that or change it.
Things I've read:
http://blogs.interakting.co.uk/post/File-Extensions-and-URL-Rewriting-in-EPiServer.aspx
http://blog.fredrikhaglund.se/blog/2008/05/07/disable-episerver-urlrewriter-interference/ (this may contain the answer I'm looking for)
http://labs.kaliko.com/2010/11/prevent-episerver-urlrewrite.html
http://sourcecodebean.com/archives/episerver-friendly-urls-for-paginated-pages-and-why-the-asplinkbutton-must-die/510
http://tedgustaf.com/en/blog/2008/7/create-a-custom-url-rewrite-provider-for-episerver/
http://tedgustaf.com/en/blog/2011/4/publishing-plain-html-pages-in-episerver/
http://sdk.episerver.com/library/cms5/Developers%20Guide/Friendly%20URL.htm
http://sdk.episerver.com/library/cms6.1/html/T_EPiServer_Web_UrlRewriteModule.htm
http://labs.episerver.com/en/Blogs/Ruwen/Dates/111218/112064/112154/
http://world.episerver.com/Blogs/Magnus-Strale/Dates/2011/3/Do-we-really-need-yet-another-HTML-parser/
http://world.episerver.com/Blogs/Yugeen-Klimenko/Dates/2011/6/How-EPiServer-URL-Rewriting-works/
http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=46869
I'm open to completely different solutions for what I'm actually trying to achieve, which is as follows:
I have multiple independent sets of static html files and related image / css / js files, which I'm trying to store / publish with EPiServer. The structure of each set looks something like
setfolder/
htmlfileA.html
htmlfileB.html
css/
styles.css
images/
piccy1.png
piccy2.png
js/
magic.js
I've figured that I should create an EPiServer page for the set, and then child pages for each html file, storing the html from the files in a property of the child pages. Currently I'm storing the related static files in the PageFiles of the relevant setfolder page, as that seems to be the most logically consistent place to put them.
It's hard to give the best solution without seeing it all infront of you. But one easy way is to alter the HTML-code when you print the property to the page.
Like <%= ChangeRelativeLinks(CurrentPage["HtmlCode"] as string) %>
And in the ChangeRelativeLinks(string htmlCode) you do a regexp or similar that changes relative links and images to the pagedir as an absolute path.
If you are storing the images in PageFiles which is a Virtual Path Provider you should be able to get the url to your file simply by using the API. On the PageData class (ie CurrentPage in your template) you have a method called GetPageDirectory() which gets the page folder.
You can read more about VPP concepts here:
http://sdk.episerver.com/library/cms6.1/Developers%20Guide/Core%20Features/File%20System/File%20System%20and%20VPPs.htm
No need for a url rewrite provider for this I think.

Resources