ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

exp:query / auto<br /> / htmlentities

March 04, 2009 8:29am

Subscribe [4]
  • #1 / Mar 04, 2009 8:29am

    _Oli

    56 posts

    Hi all,

    I’m having a little problem using exp:query

    I’m fetching some results which were entered using

    "auto 
    "

    as formatting.

    When I loop through my results and print them, the line break isn’t being represented.

    I think this could be something to do with htmlentities()..?

    Any idea how to fix this?

    I print the data using {data} should I be doing something like

    <?=htmlentities(exp['data']);?>

    instead? (exp or whatever the array name exp:query would return)

    Anyone ever come across this before?

    Thank you in advance

  • #2 / Mar 04, 2009 10:04am

    Sue Crocker

    26054 posts

    _Oli, when it comes to troubleshooting items like these, it’s faster to do the testing yourself and then report back if something doesn’t work the way you expect it to.

    What is the goal of what you’re trying to do?

  • #3 / Mar 04, 2009 10:39am

    _Oli

    56 posts

    Hello,

    Sorry I did have a go myself but couldn’t find a way around it hence the post :$

    Ok, I have a weblog called directory. In there I store contact details (name, address, email…)

    The address details are entered through the publish page in a text area as below:

    Address 1
    Address 2
    Address 3

    The formatting for this field is auto br.

    On page, I fetch the entries using {exp:query} not {exp:weblog:entries}.

    With {exp:query}, when I try to print the address details, it shows as one long line instead of inserting line breaks after each address line. In the template the code is as follow:

    {exp:query sql="query in here"}
    {address}
    {/exp:query}

    And the result looks like that:

    Address 1 Address 2 Address 3

    I have tried this:

    <?=nl2br('{address}');?>

    This doesn’t work. Results still show as one line.

    I have also tried to get the records using {exp:weblog:entries} and the line breaks are there, unfortunately, I have to use {exp:query}...

    Does that make more sense?

  • #4 / Mar 04, 2009 11:38am

    Ingmar

    29245 posts

    With {exp:query}, when I try to print the address details, it shows as one long line instead of inserting line breaks after each address line.

    That would be expected behavior: All formatting options are rendered at run-time by the weblog module. If you bypass that module you need to format the results yourself.

  • #5 / Mar 04, 2009 12:07pm

    _Oli

    56 posts

    That would be expected behavior: All formatting options are rendered at run-time by the weblog module. If you bypass that module you need to format the results yourself.

    Yes, I did get that bit but I was asking how can I format with my results…?

    Like I said this:

    <?=nl2br('{address}');?>

    Doesn’t work…

    How could I get {address} in php? The weblog module is translating this tag at the moment but I should be able to get my data without using a {} tag but something like:

    <?=$data['address'] ?>

    I just need to find that what the associative array name is…?

    Anyone..? This is so simple and it’s taking me hours to work things out… :(

  • #6 / Mar 04, 2009 4:57pm

    Ingmar

    29245 posts

    If you have a linebreak in your code, it will be in the output as well. It’s probably just that HTML ignores whitespace, so you’ll need to add some HTML, like so:

    {exp:query sql="query in here"}
    {address} 
    
    {/exp:query}

    Moving to Howto.

  • #7 / Mar 04, 2009 5:19pm

    _Oli

    56 posts

    Oh god… I’m French but I didn’t think my English was that bad 😉!!!
    The line breaks are inside {address}, imagine address is the body of a blog entry, I type one line of text, hit enter to create a new line then carry on typing…

    I then try(in the template) to pull this post using exp:query and… The line breaks have gone!!!  The whole post show on one line!

    Does this make more sense?

  • #8 / Mar 04, 2009 5:42pm

    Ingmar

    29245 posts

    So you are only pulling out one article at a time? Do you’ve got a link to the site so we can see for ourselves?

    I’d simply recommend using the Typography plugin, by the way,

  • #9 / Mar 04, 2009 6:20pm

    _Oli

    56 posts

    I’m actually in bed replying to this on my phone but let me (try) to set the scene once more.
    (Btw I actually think this could be treated as a feature request more than a how to)

    I have a weblog set in ee. Each entry has a title and a body.
    Body default formating is set as auto br.

    I publish a new entry to my blog. This entry has a title and a body. The body consists of 3 lines of texts, each lines seperated by a line break so as I type my text, I press enter on my keyboard after each line.

    Now, I want to show this entry on my site, exp:weblog:entries works well, I see my entry on page, the titleis there and the body of text formated as I wanted it to be in three lines with (in the HTML) a br between each line. We is doing it’s job I’m happy.

    Next day, exp:weblog:entries isn’t good enough anymore, I need to use exp:query to pull this entry.
    I write my query, go to my page, title is there, body is there but my line breaks have gone.

    So day 1

    {exp:weblog:entries….}
    <h1>{title}</h1>
    {body}
    {/exp:weblog:entries}

    Gives me this:

    <h1>Title</h1>
    BodyLine1
    
    
    BodyLine2
    
    
    BodyLine3

    Day 2

    {exp:query….}
    <h1>{title}</h1>
    {body}
    {/exp:query}

    Gives me this:

    <h1>{title}</h1>
    bodyLine1 bodyLine2 bodyLine3

    Please tell me this makes sense now… The plugin you suggest would not sort this I don’t think….

  • #10 / Mar 04, 2009 6:48pm

    jpaylor

    84 posts

    Hi Oli,

    The EE Typography plugin should also work (very similar to the one Ingmar linked to), see http://expressionengine.com/downloads/details/ee_typography/

    For example:

    {exp:query sql="SELECT body FROM somewhere"}
    
    {exp:ee_typography formatting="br"}
    {body}
    {/exp:ee_typography}
    
    {/exp:query}
  • #11 / Mar 05, 2009 4:30am

    _Oli

    56 posts

    Hi JonnyUK,

    Thanks for your help. The plugin did the trick nicely.

    Thank you thank you thank you to all helpers 😊

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases