Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#46 2020-09-07 14:35:21

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,498
Website GitHub

Re: Tag for static section on homepage only

Hi, gu. Your journey here in the forum is important to keep as documentation, and as an aid to help others learn. I’ve been here nearly fifteen years and posted a ‘problem’ just yesterday that I couldn’t fathom, only to find the answer obvious when someone pointed out that I was using the wrong version of Textpattern that was too old for the feature I was trying to implement! Happens to us all, so don’t worry.

That said – and I don’t want to patronize you or anything here so please forgive me if it comes across that way – here are a few general Textpattern tips that might help in your orientation:

Textpattern ‘list’ tags that operate to display collections of context-aware things (articles, images, categories, sections, files, comments, and so forth) can be used in three fundamental ways:

1) As a container – a pair of opening and closing tags:

<txp:some_list_tag wraptag="div" class="my-wrapper">
   Display <txp:dynamic_facets /> of <txp:each_thing /> in the collection.
   This allows you to customise how the content of each item is laid out.
   The entire set will be wrapped in <div class="my-wrapper">list of things</div> as dictated by the tag's attributes.
</txp:some_list_tag>

(<txp:dynamic_facets /> and <txp:each_thing /> aren’t real tags, they’re just to show that you can put <txp:> tags in to display dynamic information from the database/content anywhere you like)

2) As a single self-closing tag with the form attribute:

<txp:some_list_tag form="reuse_me" wraptag="div" class="my-wrapper" />

The entire set of items will be wrapped in <div class="my-wrapper">list of things</div> as indicated by the list tag’s attributes.

Then, in Presentation>Forms, create a form (of any type) called reuse_me with tags and content such as this, that you wish to display for each item:

Display <txp:dynamic_facets /> of <txp:each_thing /> in the collection.
This also allows you to customise how the content of each item is laid out.
The same Form can be reused for other tags so it's easier to manage in future.
Change your layout or content in the form and your site updates automatically wherever this form is used.

3) As a single self-closing tag without the form attribute:

<txp:some_list_tag wraptag="div" class="my-wrapper" />

This will operate exactly as in (2) but it will use a pre-defined form name. In the case of articles, this will be one called default. So if you modify that form, you change how every article tag that uses it behaves.

So any time you want to override the default behaviour of some ‘list’ tag, you specify a form attribute so the tag will display the content in that form when your page is displayed and it encounters that tag. This concept follows in some other non-list tags too. In the case of <txp:search_input />, for example, it looks for a corresponding search_input form. If that form doesn’t exist, the tag will throw a warning (in debugging mode).

Some tags don’t accept form because they output a specific piece of information. The <txp:title /> tag, for example, will only output the article title of the current article indicated by the visitor’s /section/some-article URL. Or, if used in a form or container, the article title of each item in the collection.

So when you’re debugging a Textpattern page, you need to be mindful of how a tag is being used.

If it’s a ‘single’ (self-closing) tag, it’ll output the given context-aware content when the tag is encountered as the page is displayed.

If it’s a self-closing ‘list’ style tag and has not been given a form it will use a default form to display content for each item in the collection. The default form that will be used in each case are all mentioned in the tag docs.

If it’s a self-closing ‘list’ style tag and has been given a form, it will use that form for each item in the collection. It’s up to you to ensure that form exists and uses relevant tags for the context in which the form is used.

If the ‘list’ style tag is used as a container, then the content between the opening and closing tags will determine how each item in the collection is displayed. It’s up to you, again, to use relevant tags for the context. So, for example, if you’re displaying a list of site sections:

<txp:section_list wraptag="nav" class="site-sections">
   <a href="/<txp:section />"><txp:section title /></a>
</txp:section_list>

Is perfectly valid (although you can do the same thing with a simple self-closing tag in this case, since that’s the output the tag creates by default). But you cannot use, say, <txp:title /> in that container, because Textpattern is in “section list” context at that moment and has no idea what ‘article title’ means.

In short, be aware of context and which forms are being used for what. If I ever get stuck and not sure which form is being used, I’ll type some random text string into the top of the form I think should be in use, save it and refresh the page. If that text appears on the page, the form is in use. I can then delete the text string safe in the knowledge that the form I’m working on is the one being used in that context. This practice, although old-skool, is still quite handy, and comes into its own when you’re messing around with themes and need to be sure that the form you’re working is the one in the theme you expect.

Hope that helps.

Last edited by Bloke (2020-09-07 14:38:43)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#47 2020-09-07 17:33:01

gu
Member
Registered: 2020-08-27
Posts: 59

Re: Tag for static section on homepage only

Dear Bloke, receiving a gem like that is certainly worth making public my waffling; I write half in jest :)

In all seriousness, I have come across your contributions here on the forum and to key textpattern github material while reading up on txp and I’d like to say what a special forum this is when experts like you also stop by and help beginners with their first steps.

Thank you so much for sharing that lesson!


<!— space for hope —>

Offline

#48 2020-09-09 14:37:29

gu
Member
Registered: 2020-08-27
Posts: 59

Re: Tag for static section on homepage only

>Update: It is now in order and images of sample pages have been added to the wiki. The ‘about’ blurb contains thanks to the forum (thanks is also included in the code). I know it is a simple project, but you were all such help. Thank you again.

Here is a link to the very simple theme I built on the Zero install: https://github.com/temene/tem. The branches are not yet in order but I just wanted to stop by because it is ‘live’.
If I have made any mistakes, I would be so appreciative if you would let me know.
Thank you so much to all of you for your assistance. Please let me know if I can be of help in any way. On my end, I will be spreading the word of textpattern!

Last edited by gu (2020-09-10 18:21:58)


<!— space for hope —>

Offline

#49 2020-09-10 18:38:32

zero
Member
From: Lancashire
Registered: 2004-04-19
Posts: 1,475
Website

Re: Tag for static section on homepage only

Well, it’s certainly minimal! I noticed one or two things ~

The front page shows categories and this is the only navigation to articles, except for Search which might bring up an article in its results.

But when viewed on a narrower viewport, Search disappears as does the site name too.

You have this in your stylesheet page:

<div class="box">
<div>
<txp:link_to_home><txp:image id="2" /></txp:link_to_home>
</div>

<div>
<txp:link_to_home>
<txp:site_name float="center" />
</txp:link_to_home>
</div>

<div class="push">
<txp:output_form form="search_input" />
</div>
</div>	 

<txp:site_name /> cannot have a float="center" It is also an invalid css rule (unless it has become part of the flex css of which I know nothing). Consequently the site name and Search are positioned to the right of the image. I think you probably want to do something like this instead:

<div class="box">
<div>
<txp:link_to_home><txp:image id="2" /><br /><txp:site_name /></txp:link_to_home>
<txp:search_input />
</div>
</div>

Congratulations on creating the most minimal Textpattern site I’ve ever seen!

Last edited by zero (2020-09-10 19:12:12)


Dozy P My attempt at music

Offline

#50 2020-09-10 19:23:39

gu
Member
Registered: 2020-08-27
Posts: 59

Re: Tag for static section on homepage only

>edited to include the another key reason I chose Textpattern

Hi Zero! I smiled so much when I read your comment about the site being minimalist! I know – and also, it was my goal :) cf. building what we want, just the way we want it…

But to advertise why I chose Textpattern for this: while my ‘design’ (if we may be generous towards me for a moment) may be minimal, it is taking full advantage of inherent capacities to TXP (e.g. interlinking, the potential for multiple authors – and also because, unlike a wiki, one can change the interface: also, I will possibly change some things to cater to user vision once they join. Textpattern affords such flexibility as opposed to the readymade).

Actually, I realise I have a question: is there a max number of users on Textpattern? What happens if they all contribute at the same time?

To return to your comment about the code, yes my CSS includes flex. Also, about the narrow viewport, the CSS should take care of that, too. But I only tested it on devices I had on hand…

The “page” was such as I tried to follow the instructions on how to submit a theme. But it is possible that I did not understand.

Dear Zero, thank you for writing. I know that my project is super simple (and think I have stated that from the start) but I hope you are not disappointed! …at least amused :) Greetings!

Last edited by gu (2020-09-10 19:50:04)


<!— space for hope —>

Offline

Board footer

Powered by FluxBB