user-pic

Custom fields, template variables, and mt:Entries

Vote 0 Votes

I'm trying to use a custom field to reference an individual entry, and output (for example) the referenced entry's Title. So far, no joy. My first try went something like this:

">

Doesn't work - no output. EntryDataLinkToThis doesn't seem to be valid in this context.

So I tried wrapping everything in a template variable:

">
">

...but the variable isn't assigned any value. Outputting the custom field directly works; assigning the variable by hand works; but it seems I can't use the custom field data in this way?

Having gone around in circles, I'm now thinking there must be a simpler way of achieving what I'm after. I'm slightly surprised, however, that I don't seem able to match `` against entry basenames. That is:

...does output entry titles, but the output bears no relation to my entry data. Is there a way of getting `` to return a specific entry, controlled by data in the current entry context?

Any help appreciated. I'm very much hoping that I'm being stupid here!

Reported on Movable Type 4.2

5 Replies

| Add a Reply
  • Comments here use Markdown, but posts don't? Er... OK. That's odd. Preview or edit on new story submission would help. Meanwhile, copy-and-paste is our friend:

    I'm trying to use a custom field to reference an individual entry, and output (for example) the referenced entry's Title. So far, no joy. My first try went something like this:

    <mt:Entries field:reference="<mt:EntryDataLinkToThis>">
        <mt:EntryTitle>
    </mt:Entries>
    

    Doesn't work - no output. EntryDataLinkToThis doesn't seem to be valid in this context.

    So I tried wrapping everything in a template variable:

    <mt:Var name="RefLink" value="<mt:EntryDataLinkToThis>">
    <mt:Entries field:reference="<mt:Var name="RefLink">">
        <mt:EntryTitle>
    </mt:Entries>
    

    ...but the variable isn't assigned any value. Outputting the custom field directly works; assigning the variable by hand works; but it seems I can't use the custom field data in this way?

    Having gone around in circles, I'm now thinking there must be a simpler way of achieving what I'm after. I'm slightly surprised, however, that I don't seem able to match <mt:Entries> against entry basenames. That is:

    <mt:Entries basename="[query]">
        <mt:EntryTitle>
    </mt:Entries>
    

    ...does output entry titles, but the output bears no relation to my entry data. Is there a way of getting <mt:Entries> to return a specific entry, controlled by data in the current entry context?

    Any help appreciated. I'm very much hoping that I'm being stupid here!

  • OK, so I can assign the variable successfully via mt:SetVarTemplate or mt:SetVarBlock, but it still doesn't evaluate in the mt:Entries tag.

  • I believe you can use $bar, so you get this:

    <mt:Var name="bar" value="foo">
    <mt:Entries field:reference="$bar">
       ...
    </mt:Entries>
    

    Can't test at the moment however.

  • Yes! You star - that works a treat.

    It looks like I still have to pass the customfield reference via a template variable, but you're absolutely right: dropping all the <mt:Var ...> stuff and using $[variable name] does evaluate in context.

    That's a day of head-bashing solved. Huge thanks, Richard!

Add a Reply

Forum Groups