Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2017-06-07 17:21:05

pexman
Member
Registered: 2016-02-27
Posts: 61

Images using a form

My code is:


<!--         APP  start        -->
<div class="container_h">
<txp:images category="slam16" break="li" wraptag="ul" class="gallery-index" sort="rand()" limit="32">

  <!-- reset variables, so the value from the last loop is not used -->
  <txp:variable name="has-matching-article" value="" />

   <!-- store the permlink of the article id that matches the current image id -->
  <txp:variable name="has-matching-article"><txp:article_custom id='<txp:image_info type="id" />'>
   <txp:permlink /></txp:article_custom></txp:variable>

  <!-- was a permlink stored? -->
  <txp:if_variable name="has-matching-article" value="">

    <!-- no: use url for the large image -->
    <txp:variable name="img-link"><txp:image_url /></txp:variable>
  <txp:else />

    <!-- yes: use the url for the matching article -->
    <txp:variable name="img-link"><txp:variable name="has-matching-article" /></txp:variable>
  </txp:if_variable>

  <!-- build the thumbnail slide -->
  <a href="<txp:variable name="img-link" />" title="<txp:image_info type="alt" />">
    <img src="<txp:image_url thumbnail="1" />"
         width="<txp:image_info type="thumb_w" />"
         height="<txp:image_info type="thumb_h" />"
         alt="<txp:image_info type="alt" />" >
  </a>
</txp:images>
</div>
<!--         APP end           -->

for an idea of this code, you can see here the result:
arteurope.de

If you choice a thumb it goes large. The code is here:


 <!-- was a permlink stored? -->
  <txp:if_variable name="has-matching-article" value="">

    <!-- no: use url for the large image -->
    <txp:variable name="img-link"><txp:image_url /></txp:variable>
  <txp:else />

    <!-- yes: use the url for the matching article -->
...

I want the images, which are not used in an article, become large in an extra form, but all I have tried doesn`t succeed. Perhaps you can give me a tip. I suspect I think too complicate about that little problem.

Last edited by pexman (2017-06-07 17:22:10)

Offline

#2 2017-06-07 18:02:37

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,305

Re: Images using a form

One thing you could try: Remove a simple return, namely between
<txp:variable name="has-matching-article"><txp:article_custom id='<txp:image_info type="id" />'>
and
<txp:permlink /></txp:article_custom></txp:variable>

The return never makes the test @<txp:if_variable name=“has-matching-article” value=”“>@ result in true.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#3 2017-06-07 18:08:49

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,305

Re: Images using a form

Return PLUS any whitespace characters, BTW.


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#4 2017-06-08 19:52:57

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,616
Website

Re: Images using a form

An aside to the above: getting image id#s to match article id#s can work but it gets harder and harder to keep up if you don’t have exact parity between the number of images and number of articles.

You might want to try a mini plugin of mine jcr_image_custom (v4.6+) which adds a single custom field to the image info panel which you could use to store the number of the relevant article id# to link to.


TXP Builders – finely-crafted code, design and txp

Offline

#5 2017-06-09 17:41:55

pexman
Member
Registered: 2016-02-27
Posts: 61

Re: Images using a form

Yes Jakob, that gets realy a problem. Thank you for your answers, but I have to confess, that I can`t understand the post of uli: how can I make a “return”???

I have some more days time to update my site, but it is not so much time, so I decided to live with the pictures without a special form. But if your plugin works, it could me save much time, because it happens more and more, that I have to change id-numbers in the database.

Offline

#6 2017-06-09 18:45:01

uli
Moderator
From: Cologne
Registered: 2006-08-15
Posts: 4,305

Re: Images using a form

pexman wrote #305899:

how can I make a “return”???

You don’t have to make a return, I adviced to remove it. Like I wrote in my first post: Remove the return character (PLUS any white space character like tabs and spaces) from between the tags I posted. If you leave only 1 space (or 1 tab or return) you will never have nothing in your test line <txp:if_variable name="has-matching-article" value="">, because you will have one of these characters in your variable. And the test will always return: No, “has-matching-article” is not empty. (Hope that helps.)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#7 2017-06-09 20:42:20

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,616
Website

Re: Images using a form

As far as I can tell, you’re trying to link selected images back to a respective article.

If you install the plugin, it should add an extra field to the image details on the image edit panel. Use that to store the article ID number of the article you wish to associate with the image. See also the instructions to change the name of the field label.

Then you’d modify your existing form as follows:

<!--         APP  start        -->
<div class="container_h">
<txp:images category="slam16" break="li" wraptag="ul" class="gallery-index" sort="rand()" limit="32">

  <!-- set "has-article" variable. Is empty if no id specified -->
  <txp:variable name="has-article"><txp:jcr_image_custom /></txp:variable>

  <!-- does image have linked article? -->
  <txp:if_variable name="has-article" value="">

    <!-- no: use url for the large image -->
    <txp:variable name="img-link"><txp:image_url /></txp:variable>

  <txp:else />

    <!-- yes: use the url for linked article id -->
    <txp:variable name="img-link"><txp:permlink id='<txp:jcr_image_custom />' /></txp:variable>

  </txp:if_variable>

  <!-- build the thumbnail slide -->
  <a href="<txp:variable name="img-link" />" title="<txp:image_info type="alt" />">
    <img src="<txp:image_url thumbnail="1" />"
         width="<txp:image_info type="thumb_w" />"
         height="<txp:image_info type="thumb_h" />"
         alt="<txp:image_info type="alt" />" >
  </a>
</txp:images>
</div>
<!--         APP end           -->

I think that should work…


TXP Builders – finely-crafted code, design and txp

Offline

#8 2017-06-09 22:34:52

pexman
Member
Registered: 2016-02-27
Posts: 61

Re: Images using a form

This works perfectly. Thank you very much for this plugin.

Offline

#9 2017-06-12 10:20:12

pexman
Member
Registered: 2016-02-27
Posts: 61

Re: Images using a form

Now I have the possibility to link more pictures to one article, in the case of more than one article-image. Second, I don`t have to edit the database, means more security, thank you.

Offline

Board footer

Powered by FluxBB