Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2023-02-18 16:46:34

Registered: 2023-02-17
Posts: 108

section position

What I did is added new column into txp_section called location, varchar (15), (top, left, right,bottom) then modified taghandlers.php and added

function section_list($atts, $thing = null)
        'active_class'    => '',
        'break'           => br,
        'class'           => __FUNCTION__,
        'default_title'   => $sitename,
        'exclude'         => '',
        'form'            => '',
        'html_id'         => '',
        'include_default' => '',
        'sections'        => '',
        'sort'            => '',
        'wraptag'         => '',
        'offset'          => '',
        'limit'           => '',
        'location'        => '',      //-< added new 
    ), $atts));

if (!$include_default) {
        $sql[] = "name != 'default'";
/// new lines added below 
if ($location!='') 
       $sql[] = "location ='". $location ."'"; 
    } else
		$sql[] = "location = 'top'";

now I can list section on top (default) if need left sections just do this:

<txp:section_list wraptag="ul" break="li" location="bottom" />  // I use this for footer
<txp:section_list wraptag="ul" break="li" location="left" />  

Right now section position only on top, when you have many of them, will look ugly, but what my addition can have extra sections, anywhere on the page.
possible there is something like , but I couldn’t find any help.
will be nice to add this feature on the next version.

BTW: I added the new column to admin section list, and add/edit section , but still working on the view to select option, not showing yet on selectInput.
at least works for me.



#2 2023-02-18 22:27:34

From: Germany
Registered: 2005-01-20
Posts: 4,431

Re: section position

Here are two ways you could achieve the same without hacking the core, which runs the risk of being overwritten in the next Textpattern update, breaking your site if you don’t remember to carry modifications over to the new version.

I (personally) think your use case is too specific to warrant being adopted in the core, but the ability to group/filter sections by whatever criteria (like you can for articles with categories or custom fields) is, I think, a valid idea.

Thankfully, you can achieve your use case using built-in options:

Option 1: predefine which sections should appear where

Define the list of sections that should occur at the respective locations as txp:variables at the top of your page, then use the variables to control the section_list output.

For example, somewhere near the top of the page include:

<txp:variable name="sections_top">default,articles,nine,three</txp:variable>
<txp:variable name="sections_right">six</txp:variable>
<txp:variable name="sections_bottom">eight,five,one,ten</txp:variable>
<txp:variable name="sections_left">eleven,four,seven,two</txp:variable>

(where one, two, three … etc. are your section names). I usually put these kinds of things in a misc form called page_vars and insert it using <txp:output_form form="page_vars" /> right at the top of the page template)

Now you can use the variables in your page template where you need them, for example:

    <txp:section_list sections='<txp:variable name="sections_top" />' wraptag="ul" break="li" />
    <txp:section_list sections='<txp:variable name="sections_left" />' wraptag="ul" break="li" />
    <txp:section_list sections='<txp:variable name="sections_right" />' wraptag="ul" break="li" />
    <txp:section_list sections='<txp:variable name="sections_bottom" />' wraptag="ul" break="li" />

Note the use of single-quotes for sections attribute. That means “process the tag within the attribute and put the result here”.

Option 2: Specify the location in each section’s settings

For this, you can use my plugin jcr_section_custom (txt installer here) which allows you to add user-editable custom fields to sections.

First, install the plugin in Admin › Plugins by pasting the contents of the txt installer linked above into the textarea and clicking Upload and ‘OK’ the installation. Then activate the plugin by clicking on it in the “Active” column so that it says “Yes” under active.

Now visit Admin › Preferences and you will see a new preferences group called “Section custom fields”. Set Section custom field 1 name to location and save.

Now go to Admin › Languages and paste the following into the Install Textpack textarea at the bottom of the page:

#@owner jcr_section_custom
#@language en, en-gb, en-us
jcr_sec_custom_1 => Location

(if you’re working in another language, use your own language’s initials and your own translation). This just gives you a more human-readable label in the admin area. This is a one-time setup.

From now on, you will see a new field at the bottom of each edit section panel called Location. Here you can enter top, left, bottom, right (or any way of grouping them) for each section. The location of a section will now be saved with each section.

Now all you need to do is compile these settings into a list of sections in each location as variables, and you can use the same method as in Option 1 to output them where you want them on the page.

Somewhere near the top of the page (or in your page_vars form), insert the following

<txp:section_list break="">
    <txp:jcr_if_section_custom name="location">
        <txp:variable name='sections_<txp:jcr_section_custom name="location" />' add='<txp:section />' separator="," />

This loops over all the sections you have and if your “location” custom field contains a value, it builds the variable for each location by appending the current section’s name to the end of a variable called sections_{location}. If you’ve consistently used top, right, bottom, left as your values, you’ll end up with the same variables shown in Option 1, except that these have been compiled from the respective section’s settings.

TXP Builders – finely-crafted code, design and txp


#3 2023-02-18 22:45:54

Registered: 2023-02-17
Posts: 108

Re: section position

Thank you for your time and sharing the solution, yup that works, but I hoped to add this feature in the future without doing extra coding :)


#4 2023-02-19 10:15:55

Registered: 2010-11-11
Posts: 4,859
Website GitHub

Re: section position

lindabb wrote #334670:

I hoped to add this feature in the future without doing extra coding :)

Sections will possibly have custom fields in a future version, that one could (ab)use at will.


Board footer

Powered by FluxBB