Advertisement

Template for article

Need help with the Administration of your Joomla! 5.x site? This is the spot for you.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10
Post Reply
gerner
Joomla! Apprentice
Joomla! Apprentice
Posts: 21
Joined: Wed Nov 15, 2017 3:50 pm

Template for article

Post by gerner » Tue Oct 29, 2024 4:34 pm

Hi

I need to make an article template that will be used for many (+100 pages)
The article should show the info I enter when I create the article. I have created some custom fields like the below under "create article":
Location:
Fish type:
Food:
Size:
Famely:
That will be a part of the article page.

How ever the page will be with a photo in the left side and the fact info from above in the right side of the page.

Question is:
Do I need to code the article page for each article I create or is it possible some how to create a template that I can link to from the menu and then the article is using the template I wish to use - Just as now in the menu when I choose an article to link to.
Or is there an otherway to do this?

its difficult to explain but hope you understand what I mean :)

Thanks
/Gert

Advertisement
gws
Joomla! Champion
Joomla! Champion
Posts: 6460
Joined: Tue Aug 23, 2005 1:56 pm
Location: South coast, UK
Contact:

Re: Template for article

Post by gws » Tue Oct 29, 2024 4:50 pm

Brian Teeman shows how to make article templates in tinymce in one of the magazine articles, you will have to search through to find it.

gerner
Joomla! Apprentice
Joomla! Apprentice
Posts: 21
Joined: Wed Nov 15, 2017 3:50 pm

Re: Template for article

Post by gerner » Tue Oct 29, 2024 6:45 pm

Thx, I found the article here:
https://magazine.joomla.org/all-issues/ ... lready-had

Anyway I need template to place the info from my custom fields
(I have created under Content and Fields:
Location:
Fish type:
Food:
Size:
Famely:)

where I want it to be displayed in a table.

Right now I just show op in the top of a created article. Is that possible to move it to for an example in a table, by addning a code to the template where I want it to show up?

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 17920
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Template for article

Post by toivo » Tue Oct 29, 2024 9:13 pm

If you want to change the way how the custom fields are presented in the article layout, create a template override and modify the PHP code for the article view: Template Overrides

Brian Teeman has also developed a method to create installable Joomla child templates that contain template overrides, which looks interesting: Template Overrides - Recycle and reuse
Toivo Talikka, Global Moderator

gerner
Joomla! Apprentice
Joomla! Apprentice
Posts: 21
Joined: Wed Nov 15, 2017 3:50 pm

Re: Template for article

Post by gerner » Mon Nov 04, 2024 6:22 pm

toivo wrote: Tue Oct 29, 2024 9:13 pm If you want to change the way how the custom fields are presented in the article layout, create a template override and modify the PHP code for the article view: Template Overrides

Brian Teeman has also developed a method to create installable Joomla child templates that contain template overrides, which looks interesting: Template Overrides - Recycle and reuse
I see - Thanks. I have tried to figure out what file to make a copy of and start changing the codes in, to make a new predefined layout. What I have done:

1: in Templates: Customise (Cassiopeia) I have tried to create an override of the original default article page. I have made an override of the below files and add some codes:
Components -> com_content -> article
Modules -> mod_articles

2: when i choose an article (already made) and go to the tab Options and choose the new Layout I just have made, save it, I cant see the changes I made in the files above.

So my question is, im I changing the codes in the wrong file or what im I doing wrong?

User avatar
toivo
Joomla! Master
Joomla! Master
Posts: 17920
Joined: Thu Feb 15, 2007 5:48 am
Location: Sydney, Australia

Re: Template for article

Post by toivo » Tue Nov 05, 2024 5:31 am

gerner wrote: Mon Nov 04, 2024 6:22 pmI have tried to figure out what file to make a copy of and start changing the codes in, to make a new predefined layout.
If you follow the tutorial Template Overrides, the article view that can be modified is the file templates/cassiopeia/html/com_content/article/default.php.

If you want to modify the module Articles, the override file is stored as templates/cassiopeia/html/mod_articles/default.php but the override also includes the file default_items.php and default_titles.php.
Toivo Talikka, Global Moderator

gerner
Joomla! Apprentice
Joomla! Apprentice
Posts: 21
Joined: Wed Nov 15, 2017 3:50 pm

Re: Template for article

Post by gerner » Wed Nov 06, 2024 5:50 pm

Thanks. I have tried to make an override file called TEST-TEMPLATE.php. Its placed here:
templates/cassiopeia/html/com_content/article/TEST-TEMPLATE.php

Now if I open an article, go to the tab "Options" and change the layout from "Use Global" to TEST-TEMPLATE it does not change anything on the article page on my website.

Do I understand this wrong? I understood that I could make serval layout for articles and then choose what layout under the tab "Options" I wanted to use on an given article?

BTW if I make a test template and upload it under:
templates/cassiopeia/html/mod_articles/
Im not able to choose anywhere that I want to use that for a given article.

Hope it make sense what I mean :)

gws
Joomla! Champion
Joomla! Champion
Posts: 6460
Joined: Tue Aug 23, 2005 1:56 pm
Location: South coast, UK
Contact:

Re: Template for article

Post by gws » Wed Nov 06, 2024 6:31 pm

I believe your override file names have to be the same as the file you are overriding.

Mr. Wimpy
Joomla! Guru
Joomla! Guru
Posts: 586
Joined: Fri Dec 02, 2005 10:46 am
Location: The Netherlands

Re: Template for article

Post by Mr. Wimpy » Thu Nov 07, 2024 9:18 am

Yes and no.

When you use default.php the override will apply to all default article pages.

When you want specific articles from a blog or list to have an override, you need to give it a different name.

Give the file a simple name. I.e. food.php, fish.php, whateveryouliketonameit.php
You cannot use special characters, so no dashes, underscores*, etc. in the name.
* underscores have a specific use in overrides.

You then select this override in your category blog/list menu item, under Options: Choose a layout.
All articles linked from this menu item will use the override.

gerner
Joomla! Apprentice
Joomla! Apprentice
Posts: 21
Joined: Wed Nov 15, 2017 3:50 pm

Re: Template for article

Post by gerner » Thu Nov 07, 2024 4:15 pm

Thanks for the reply.

Can you guide me a little through this:

1. I create a new new layout file called fish.php. The file will have my PHP changes I have made.

2. I upload the file to the folder /templates/cassiopeia/html/com_content/article/ (is this correct?)

3. I create a new article called Fishart.

4. In the article Fishart, I choose the tab "Options" and change the layout from "Use Global" to "fish" (is this correct?)

What do I do next? When I do the above, the article Fishart is still use the "Default" layout.

I really can't figure this out, I hope you can advice - THANKS.

Mr. Wimpy
Joomla! Guru
Joomla! Guru
Posts: 586
Joined: Fri Dec 02, 2005 10:46 am
Location: The Netherlands

Re: Template for article

Post by Mr. Wimpy » Thu Nov 07, 2024 7:24 pm

Almost...
4. The layout for articles is set in the menu-item.

Open or create a/the menu-item that displays the articles in a category blog or list.
Under tab: Options you'll find Choose a layout.
Select Fish.

gerner
Joomla! Apprentice
Joomla! Apprentice
Posts: 21
Joined: Wed Nov 15, 2017 3:50 pm

Re: Template for article

Post by gerner » Sun Nov 10, 2024 4:25 pm

Its working - Perfect Thanks.

Would it be possible to to link the menu direct to the article without linking to the blog or list? Means choose "Single Article" in menu item type.

Mr. Wimpy
Joomla! Guru
Joomla! Guru
Posts: 586
Joined: Fri Dec 02, 2005 10:46 am
Location: The Netherlands

Re: Template for article

Post by Mr. Wimpy » Mon Nov 11, 2024 9:15 am

Yes, you can.

For this you also need an xml file with the same name.
I.e. food.php and food.xml

Just copy and rename ~/components/com_content/tmpl/article/default.xml to ~/templates/your-template/html/com_content/article/food.xml

Then open this file to edit this

Code: Select all

<layout title="COM_CONTENT_ARTICLE_VIEW_DEFAULT_TITLE" option="COM_CONTENT_ARTICLE_VIEW_DEFAULT_OPTION">
  <help
    key = "Menu_Item:_Single_Article"
  />
  <message>
    <![CDATA[COM_CONTENT_ARTICLE_VIEW_DEFAULT_DESC]]>
  </message>
</layout>
to i.e.

Code: Select all

<layout title="Single Food Article" option="foodarticle">
  <help
    key = "Menu_Item:_Single_Article"
  />
  <message>
    Display a single selected food article
  </message>
</layout>
Or if you have a multilingual backend you can replace the DEFAULT_LANGUAGE_CONSTANTS with YOUR_OWN_LANGUAGE_CONSTANTS...

Advertisement

Post Reply

Return to “Administration Joomla! 5.x”