s3nior Posted November 14, 2016 Share Posted November 14, 2016 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 More sharing options...
kixe Posted November 14, 2016 Share Posted November 14, 2016 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 More sharing options...
kixe Posted November 14, 2016 Share Posted November 14, 2016 Again me. Forget about what I have written before. You could use 'Newlines to XHTML Line Breaks ', if you set the Number of rows for the description field to minimum 2 under the Input tab. Link to comment Share on other sites More sharing options...
netcarver Posted November 14, 2016 Share Posted November 14, 2016 @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. 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now