Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#16 2014-02-25 19:17:13

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,395
Website GitHub Mastodon Twitter

Re: Different info on different articles_id in a sidebar?

admi wrote #279255:

I know how to use custom_fileds. But I can not paste stuff with <div>, <p> and other html-code into a custom field.

You can but you have to use the escape attribute. ie <txp:custom_field name="someName" escape="" />


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#17 2014-02-25 19:29:32

admi
Member
From: BY
Registered: 2007-12-10
Posts: 145
Website

Re: Different info on different articles_id in a sidebar?

Well! Finally I got a revelation! I remembered this code from the default txp 4.5 head:

<txp:if_search>
    <meta name="robots" content="none">
  <txp:else />
  <txp:if_category>
    <meta name="robots" content="noindex, follow, noodp, noydir">
  <txp:else />
  <txp:if_author>
    <meta name="robots" content="noindex, follow, noodp, noydir">
  <txp:else />
    <meta name="robots" content="index, follow, noodp, noydir">
  </txp:if_author>
  </txp:if_category>
  </txp:if_search> 

And by analogy tried this:

<txp:if_article_list>
<txp:output_form form="RIGHTSIDEBAR" />
<txp:else />
<txp:if_article_id id="6">
<txp:output_form form="RIGHTSIDEBAR-for-Berlin" />
<txp:else />
<txp:if_article_id id="18">
<txp:output_form form="RIGHTSIDEBAR-for-Moscow" />
<txp:else />
<txp:if_article_id id="19">
<txp:output_form form="RIGHTSIDEBAR-for-Minsk" />
<txp:else />
<txp:output_form form="RIGHTSIDEBAR" />
</txp:if_article_id> 
</txp:if_article_id> 
</txp:if_article_id> 
</txp:if_article_list>

It works ok at first look, hope at second look as well. No error warnings. Tomorrow I will post another question as for using <txp:if_article_id>

Last edited by admi (2014-02-25 19:35:29)

Offline

#18 2014-02-25 20:15:33

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

Re: Different info on different articles_id in a sidebar?

admi wrote #279255:

I know how to use custom_fileds. But I can not paste stuff with <div>, <p> and other html-code into a custom field. Also it is difficult to locate to find what article custom field belongs. But article id is well seen in the list.

OK, sorry, didn’t mean to come across patronising. But as colak points out you can use HTML in custom fields (subject to the current 255 character limit), and if you are concerned about visibility of custom field data on the Write panel, you can use bot_write_tab_customize to change the layout.


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

#19 2014-02-25 20:33:48

admi
Member
From: BY
Registered: 2007-12-10
Posts: 145
Website

Re: Different info on different articles_id in a sidebar?

Bloke wrote #279261:

OK, sorry, didn’t mean to come across patronising. But as colak points out you can use HTML in custom fields (subject to the current 255 character limit), and if you are concerned about visibility of custom field data on the Write panel, you can use bot_write_tab_customize to change the layout.

That’s Ok. I dont mind patronising from the guys who know more than I do. What about the code that I used above? From your and TXP point of view does it look all right?

Offline

#20 2014-02-25 20:59:00

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: Different info on different articles_id in a sidebar?

The concern with the code you posted would be what if in the future you need a “Right Sidebar for New Mexico”. You’ll need a new form to go with that article and you’ll need a new if_article_id tag.

Custom fields would allow you to store the sidebar info with each article.


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#21 2014-02-25 21:10:15

admi
Member
From: BY
Registered: 2007-12-10
Posts: 145
Website

Re: Different info on different articles_id in a sidebar?

MattD wrote #279265:

The concern with the code you posted would be what if in the future you need a “Right Sidebar for New Mexico”. You’ll need a new form to go with that article and you’ll need a new if_article_id tag.

Custom fields would allow you to store the sidebar info with each article.

well, i will try both ways. I like article_ids cause articles are well seen in the article list and it is logical continuation of if_section, if_category, if_article_list, if_individual_article…. also how do you edit stuff in several paragraphs in a custom_field if needed – that’s a real hell.

Offline

#22 2014-02-25 21:15:02

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

Re: Different info on different articles_id in a sidebar?

admi wrote #279263:

What about the code that I used above? From your and TXP point of view does it look all right?

Sure, it’ll work. Because your first else statement makes sure Txp is in individual article context so it can access the article data. But it’s not very clean, and will be hard to maintain in future, as MattD says.

That’s why we’re trying to figure out what, exactly, you want to show in the sidebar — what sort of markup — because I still think you’ll be better off collecting the content if at all possible, and keeping the presentation separate in the template. Mixing them in this manner works fine, but you may be able to save yourself quite a lot of conditional code and potential head scratching in six months’ time.

Anyway, let’s go back a step. You want article 6 to have a sidebar block that shows info about Berlin, article 18 to show a sidebar block about Moscow and article 19 to show a sidebar about Minsk, right? At least, that’s all for now.

The custom field approach will work, but is perhaps overkill because you only want the content in those three articles and don’t want to saddle all your articles with empty custom data. I think I see your reservation about custom fields now, but for completeness let’s work through it anyway. Assuming you want to display the office’s Location, a brief Description and a bunch of Images in the sidebar, you’d create two custom fields called location and description respectively, and edit the articles so all your content is co-located with the article to which it refers, using Article Image to hold the list of image IDs.

In your archive template you’d then do this where your block of code is above:

<div id="sidebar">
   <txp:if_individual_article>
      <txp:output_form form="article-sidebar" />
   <txp:else />
      <txp:output_form form="list-sidebar" />
   </txp:if_individual_article>
</div>

So, landing pages get your list-sidebar displayed and all articles get article-sidebar. Fine, but we need to make sure that only those three articles get the content. Since only those three articles have custom field content, you can use some conditional magic to check, inside the article-sidebar Form:

<txp:if_custom_field name="location">
   <h3>Office: <txp:custom_field name="location" /></h3>
   <p><txp:custom_field name="description" /></p>
   <txp:hide> Add any images </txp:hide>
   <txp:images wraptag="ul" break="li">
      <txp:thumbnail />
   </txp:images>
<txp:else />
   <txp:hide> Location (and, by inference, Description) not set so default to list sidebar </txp:hide>
   <txp:output_form form="list-sidebar" />
</txp:if_custom_field>

Job done.

But as I alluded earlier, that’s going to pollute your custom field pool for the sake of three articles. Your approach puts content in multiple Forms which clutters things up. So, in the interests of content separation, or at least trying to keep things grouped, how about we ditch the custom field / one-Form-per-article idea and instead be more creative in your article-sidebar Form:

<txp:hide> BERLIN </txp:hide>
<txp:variable name="sidebar-6">
   <h3>Office: Berlin</h3>
   <p>Berlin is a vibrant city full of people blah blah...</p>
   <txp:output_form form="image-sidebar">5, 3, 28, 17, 39</txp:output_form>
</txp:variable>

<txp:hide> MOSCOW </txp:hide>
<txp:variable name="sidebar-18">
   <h3>Office: Moscow</h3>
   <p>Moscow is a vibrant city full of people blah blah...</p>
   <txp:output_form form="image-sidebar">6, 11, 25</txp:output_form>
</txp:variable>

<txp:hide> MINSK </txp:hide>
<txp:variable name="sidebar-19">
   <h3>Office: Minsk</h3>
   <p>Minsk is a vibrant city full of people blah blah...</p>
   <txp:output_form form="image-sidebar">22, 1, 13, 72</txp:output_form>
</txp:variable>

<txp:hide> Only output one of the above variable blocks if it's been defined for the current article ID </txp:hide>
<txp:if_variable name='sidebar-<txp:article_id />'>
   <txp:variable name='sidebar-<txp:article_id />' />
<txp:else />
   <txp:output_form form="list-sidebar" />
</txp:if_variable>

And in image-sidebar you can take the comma-separated list of image IDs and inject them into an attribute using <txp:yield />:

<txp:images id='<txp:yield />' wraptag="ul" break="li">
   <txp:thumbnail />
</txp:images>

OK, the content isn’t tied directly to the articles, but at least it’s all contained in one Form and if you ever need to extend it, there’s only one extra place to look where all the content is collected. You could abstract the textual ‘location and description’ part out to sub-Forms too if you wished using the same yield idea. Depends how far you want to go.

Does that give you something to work with? (EDIT: none of the above is tested, btw, just off the top of my head)

Last edited by Bloke (2014-02-25 21:32:47)


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

#23 2014-02-25 22:54:15

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: Different info on different articles_id in a sidebar?

Bloke’s recommendation is a good one and removes most of my concerns. Especially if you don’t have a client or some other user who needs to update these pieces of content.


My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#24 2014-02-28 10:29:18

admi
Member
From: BY
Registered: 2007-12-10
Posts: 145
Website

Re: Different info on different articles_id in a sidebar?

MattD wrote #279273:

Bloke’s recommendation is a good one and removes most of my concerns. Especially if you don’t have a client or some other user who needs to update these pieces of content.

Thanx everybody for shedding some light on this important issue. I think it should be posted in http://txptips.com
How about this? I need to show a certain left sidebar menu on the above pages whereas on all the of pages there will be a different menu. I use this code:

<txp:if_article_list>
<txp:linklist break="li" category="leftmenu" limit="7" sort="linksort asc" wraptag="" />
<txp:else />
<txp:if_article_id id="6,18,19">
<txp:linklist break="li" category="contacts" limit="7" sort="linksort asc" wraptag="" />
<txp:else />
<txp:linklist break="li" category="leftmenu" limit="7" sort="linksort asc" wraptag="" />
</txp:if_article_id> 
</txp:if_article_list>

Is this method rational enough?

Offline

Board footer

Powered by FluxBB