[英]DOM manipulation in codeigniter before page loads
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. 有没有一种方法可以在加载之前或加载时修改视图文件的html,以便可以将包含div的元素包装在具有特定类的现有元素周围。
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');
当我通过
$this->load->view('test_view');
加载视图时,在视图文件test_view.php中的某个位置$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 然后我希望视图使用add-wrapper-to-elem类在所有元素周围加载一个额外的包装div
is this possible and how would i go about it? 这可能吗,我将如何处理?
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>
See Processing Output on the CodeIgniter docs. 请参阅CodeIgniter文档上的处理输出 。
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. 您可以使用_output函数在控制器中获取呈现的HTML,然后使用匹配项(正则表达式或其他)来查找元素并将其包装。
See Using regular expressions to extract content on askaboutphp. 请参阅使用正则表达式提取askaboutphp上的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.