We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: Single Field

Development and Programming

Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi,

Single Field is used most often together with other plugins when you need to output content of some field but there is no need for powerful machinery of exp:weblog:entries. Single Field also uses less PHP memory and SQL calls than exp:weblog:entries.

       
Derek Hogue's avatar
Derek Hogue
316 posts
16 years ago
Derek Hogue's avatar Derek Hogue

Laisvunas - I encountered an undefined index error with your plugin, and figured out why. Basically, if an entry_id was passed that was bad (non-existent), it was still looking for field formatting for the returned row. I fixed it by moving the block starting at IV. Format field value into the

if ($query4->num_rows == 1)

block of code (around line 133), so it only looks for the field formatting if there was indeed a result of the query.

Thanks for the plugin, very useful!

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi D-Rock,

Thanks for your bug report and correct suggestion concerning fix.

I also found and fixed analogous bug - nonexistent custom field name resulting into MySQL error message being shown.

Now both fixes are incorporated into 1.0.1 version of Single Field plugin.

       
drpudding's avatar
drpudding
58 posts
16 years ago
drpudding's avatar drpudding

Laisvunas,

I think I tracked down the source of my errors, which we earlier discussed in the Child Categories thread. There are nested quote issues I’m seeing, which appear to relate to using the following type of test with the single field plug in:

{if "{exp:single_field field="field_name" weblog="resources" entry_id="{entry_id}"}"} do something {/if}

There are cases where the single field plugin will render quotes for the tested field, thus leading to quotes inside quotes, and T_STRING errors:

  1. If the data being tested is an http address or contains an http address (e.g. http://site.com), then it is auto-converted like so (Despite if the weblog prefs are set to NOT auto-convert URLs/emails):

{if "<a hreff="http://site.com">http://site.com</a>"} – quotes inside quotes.

Field format does not appear to affect this.

  1. If the data being tested contains quotes itself, then you will get the same problem. This can be overcome by setting the field format to xhtml in the test condition:
{if "{exp:single_field field="field_name" weblog="resources" entry_id="{entry_id}" field_format="xhtml"}"} do something {/if}

So I’m wondering if anything can be done about #1.

Marc

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi Mark,

Try to use single quotes instead of double ones, that is instead of

{if "{exp:single_field field="field_name" weblog="resources" entry_id="{entry_id}"}"} do something {/if}

write

{if '{exp:single_field field="field_name" weblog="resources" entry_id="{entry_id}"}'} do something {/if}

or

{if '{exp:single_field field="field_name" weblog="resources" entry_id="{entry_id}"}' != ''} do something {/if}
       
drpudding's avatar
drpudding
58 posts
16 years ago
drpudding's avatar drpudding

Laisvunas –

Yes. Single quotes work so long as you ALSO use field_format=”xhtml”

{if '{exp:single_field field="field_name" weblog="resources" entry_id="{entry_id}" field_format="xhtml"}'} do something {/if}

I will test some more, but it looks good.

Thanks, again!

       
smartpill's avatar
smartpill
456 posts
16 years ago
smartpill's avatar smartpill

I’m having a problem using this when the content contains an email link. The code is being output as

“feedback”

which was originally:

{encode="[email protected]" title="feedback"}

I’m using:

{exp:single_field  field="misc_text" entry_id="18" field_format="xhtml"}

Is there a way to make it render properly or is this a bug?

       
timkelty's avatar
timkelty
177 posts
15 years ago
timkelty's avatar timkelty

I was having trouble with entries with html in them being espaced, because the Typography class defaults to ‘safe’ HTML allowed only.

I added the following to remedy:

$parse_options = array(
              'text_format' => $field_format,
              'html_format'   => 'all',
              'auto_links'    => 'n',
              'allow_img_url' => 'y',
              'parse_images' => 'y',
            );
            $field_value = $TYPE->parse_type($field_value, $parse_options);
       
Laisvunas's avatar
Laisvunas
879 posts
15 years ago
Laisvunas's avatar Laisvunas

Hi all,

I released version 1.1 of Single Field plugin.

In this release several new parameters were added allowing more control over formatting of the field values: “allow_img_url”, “auto_links”, “encode_email”, “encode_type”, “html_format” and “parse_smileys”.

About using these parameters read in the first post of this thread.

Thanks to timkelty for suggesting this improvement.

       
tpayton's avatar
tpayton
172 posts
15 years ago
tpayton's avatar tpayton

Love Single Field. However, I can’t seem to find a way to pull the “title” field. Is it possible?

       
timkelty's avatar
timkelty
177 posts
15 years ago
timkelty's avatar timkelty

You could always use Low’s ‘Title’ plugin.

       
tpayton's avatar
tpayton
172 posts
15 years ago
tpayton's avatar tpayton

Fantastic! Thanks!

       
Mark Terpstra's avatar
Mark Terpstra
205 posts
15 years ago
Mark Terpstra's avatar Mark Terpstra

When using Single Field with a Date field type - is it possible to control the date format?

Right now the date is output like this: 1265152989 But I’d like to display it like this: February 02, 2010

This is my code:

{exp:single_field field="restock_date" entry_id="{entry_id}" site="1" field_format="none"}
       
Laisvunas's avatar
Laisvunas
879 posts
15 years ago
Laisvunas's avatar Laisvunas

Hi Mark,

Single field plugin does not aim at outputting content of such field as {title}, {url_title} or {date}; it aims solely at outputting content of single custom field.

       
Mark Terpstra's avatar
Mark Terpstra
205 posts
15 years ago
Mark Terpstra's avatar Mark Terpstra
Hi Mark, Single field plugin does not aim at outputting content of such field as {title}, {url_title} or {date}; it aims solely at outputting content of single custom field.

Actually it is a custom field but the field type is “Date” - so it outputs the raw date, but I was wondering if I could do date variable formatting. It’s not a big deal either way.

       
1 2 3

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.