2

is there a way to modify the html of a view file before or as it is loaded, such that a containing div element can be wrapped around existing elements that have a particular class.

So as an example:

if i have the element

<div class="add-wrapper-to-this-elem">

</div>

somewhere within the view file test_view.php, when i load the view via $this->load->view('test_view'); i would then like the view to load with an extra wrapper div around all elements with the class of add-wrapper-to-elem

is this possible and how would i go about it?

Jai
  • 2,096
  • 5
  • 25
  • 37

2 Answers2

1

You can create a wrapper view file with content and load this view instead:

<div class="add-wrapper-to-this-elem">
          <?php $this->load->view('test_view');?>
</div> 
sushil
  • 2,641
  • 3
  • 18
  • 24
0

See Processing Output on the CodeIgniter docs.

You can use the _output function to get rendered HTML in your controller and then use matching (regex or otherwise) to find your elements and wrap them.

See Using regular expressions to extract content on askaboutphp.

Andrew Grothe
  • 2,562
  • 1
  • 32
  • 48
  • [Don't parse html with regex](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags), use an XML parser like [PHP DOM](http://php.net/manual/en/class.domdocument.php) – Joe Flynn Jun 29 '12 at 13:03