Jump to content

image description line 2 with <br>


s3nior
 Share

Recommended Posts

Hello,

i have a image field and the description has two lines.
The first line should be the name and the second line should be the emailadress .
 

<span class='slider__caption'><strong>$image->description</strong> <br> email@info-email.com</span>

Is it possible to get the second line from the description field?
Do you have any Ideas?

looking forward to get any hints.

best regards

s3nior

Link to comment
Share on other sites

Under the Details tab in the Image field settings you could add textformatters to the description field.

You could use 'Newlines to XHTML Line Breaks '. (Edit: Inputfield doesn't accept newlines)

You could use Ryans Textformatter Hanna Code and create your own replacements.
http://modules.processwire.com/modules/process-hanna-code/

or more simple:

<?php

/**
 * ProcessWire 'slashN2br' Textformatter
 * @author Christoph Thelen (kixe)
 *
 * ProcessWire 3.x, Copyright 2016 by Ryan Cramer
 * https://processwire.com
 *
 */

class slashN2br extends Textformatter {

    public static function getModuleInfo() {
        return array(
            'title' => "string '\\n' to <br/>",
            'version' => 100,
            'author' => 'kixe',
            'summary' => "Converts the string '\\n' to XHTML line break <br /> tags. Useful in image description fields",
        );
    }

    public function format(&$str) {
        $str = str_replace(array('\n'), '<br/>', $str);
    }
}

Save the code under /site/modules/slashN2br.module
Not tested.

Link to comment
Share on other sites

@s3nior

If you want to split the content of the field up by lines, you can use the PHP explode() function with "\n" (probably) as the $delimiter; something like this...

$lines = explode("\n", $image->description); // $lines is now an array of strings, indexing starts at zero
$second_line = $lines[1];

echo "Second line is: $second_line";

Hope that helps.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...