Skip to content

Commit 5c47c7d

Browse files
committed
Added wrapLinesInTag function
This wraps any lines in multiline text in a tag your choosing.
1 parent 5a27aa2 commit 5c47c7d

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Template Tools
22

33

4-
[![version 1.1](https://img.shields.io/badge/version-1.1-brightgreen.svg)](https://github.com/ianisted/template-tools)
4+
[![version 1.1.1](https://img.shields.io/badge/version-1.1.1-brightgreen.svg)](https://github.com/ianisted/template-tools)
55

66

77
A Craft plugin to provide twig filters to help with template building.
@@ -65,3 +65,12 @@ Add a flag of true to remove the P tags from the content.
6565
```
6666
{{ content|getFirstParagraph(true) }}
6767
```
68+
69+
70+
## wrapLinesInTag
71+
72+
This wraps any lines in multiline text in a tag your choosing.
73+
74+
```
75+
{{ content|wrapLinesInTag('span') }}
76+
```

templatetools/TemplateToolsPlugin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ function getName()
1010

1111
function getVersion()
1212
{
13-
return '1.1.0';
13+
return '1.1.1';
1414
}
1515

1616
function getDeveloper()

templatetools/twigextensions/TemplateToolsTwigExtension.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ public function getFilters()
1717
return array(
1818
'firstTag' => new Twig_Filter_Method($this, 'firstTag'),
1919
'getFirstParagraph' => new Twig_Filter_Method($this, 'getFirstParagraph'),
20+
'wrapLinesInTag' => new Twig_Filter_Method($this, 'wrapLinesInTag'),
2021
);
2122
}
2223

@@ -59,4 +60,11 @@ public function getFirstParagraph($html,$stripP = false)
5960
}
6061

6162

63+
public function wrapLinesInTag($html,$tag)
64+
{
65+
$return = '<' . $tag . '>'.str_replace(array("\r","\n\n","\n"),array('',"\n","</$tag>\n<$tag>"),trim($html,"\n\r")).'</' . $tag . '>';
66+
return TemplateHelper::getRaw($return);
67+
}
68+
69+
6270
}

0 commit comments

Comments
 (0)