Remove content inside of template hook

  • Thread starter Thread starter ragtek
  • Start date Start date
R

ragtek

Guest
Is there a way to remove the complete <dl ... </dl> block in this code: (template account privacy ) with template hooks?

Code:
<xen:hook name="account_privacy_top">
<!-- start remove -->
    <dl class="ctrlUnit surplusLabel">
        <dt><label>{xen:phrase activity_display}:</label></dt>
        <dd>
            <ul>
                <li><label for="ctrl_visible"><input type="checkbox" name="visible" value="1" id="ctrl_visible" class="OptOut" autofocus="autofocus" {xen:checked "{$visitor.visible}"} /> {xen:phrase show_your_online_status}</label> <p class="hint">{xen:phrase this_will_allow_other_people_to_see_what_page_you_currently_viewing}</p></li>
            </ul>
        </dd>
    </dl>
<!-- end remove -->
<xen:hook name="account_privacy_top">

I could add 2 listeners with very high priority so they're run as first which insert
Code:
<!--
at account_privacy_top
and
Code:
-->
at account_privacy_top but that's IMO very ugly and could conflict with other add-ons using the same hook and same priority.


I really wish we would get something similar like vB TMS :(
 
Post template and do strpos on <dl class="ctrlUnit surplusLabel"> and then the first </dl> after that. Then do a substr. That is assuming <dl class="ctrlUnit surplusLabel"> is unique. If it isn't then you will have to simple add some more code until it is unique. Another option is manipulating the DOM on the server side.
 
Post template and do strpos on <dl class="ctrlUnit surplusLabel"> and then the first </dl> after that. Then do a substr. That is assuming <dl class="ctrlUnit surplusLabel"> is unique. If it isn't then you will have to simple add some more code until it is unique. Another option is manipulating the DOM on the server side.
the problem is, there are several
Code:
<dl class="ctrlUnit surplusLabel">
inside of the hook

Also i can't say "remove the first,second or third element" because the script can't know on what position the box is, which should be removed, if there are other add-ons adding an output there... :(
 
What I would do is create the DOM and loop through and get the dl that has the label inner HTML of...
Code:
new XenForo_Phrase('activity_display') . ':'

Very annoying process and would obviously have extra overhead added however there isn't much more you can do. I think that would solve the problem if other add-ons add there?

What I will be doing in the future is adding notes for how people can do the template edits manually to get a performance boost if they see any slowdown from the DOM manipulation. Best way I can think of doing things until proper modifying is done to the templates via add-ons.
 
It's not possible to search for the phrase on template_post_render because the template is already rendered/parsed there:(


Edit: ok some hackish code did it

thx
 
Don't forgot you probably need to add a hidden input there otherwise submitting it will yield a zero by the input cleaner, which would then be saved as not visible. :)

I actually did something similar... removing the option, but I just decided to hide the options everywhere I needed with CSS. That way I didn't need to muck with dealing with the current code expecting to see the value on submission.
 
To delete the Contenst it should work, that unset $contents inside the Listner Class.
 
To delete the Contenst it should work, that unset $contents inside the Listner Class.
No, this would remove:
PHP:
    <xen:hook name="account_privacy_top">

    <dl class="ctrlUnit surplusLabel">
        <dt><label>{xen:phrase activity_display}:</label></dt>
        <dd>
            <ul>
                <li><label for="ctrl_visible"><input type="checkbox" name="visible" value="1" id="ctrl_visible" class="OptOut" autofocus="autofocus" {xen:checked "{$visitor.visible}"} /> {xen:phrase show_your_online_status}</label> <p class="hint">{xen:phrase this_will_allow_other_people_to_see_what_page_you_currently_viewing}</p></li>
            </ul>
        </dd>
    </dl>

    <dl class="ctrlUnit surplusLabel">
        <dt><label>{xen:phrase administrator_email}:</label></dt>
        <dd>
            <ul>
                <li><label for="ctrl_receive_admin_email"><input type="checkbox" name="receive_admin_email" value="1" id="ctrl_receive_admin_email" class="OptOut" {xen:checked "{$visitor.receive_admin_email}"} /> {xen:phrase receive_site_mailings}</label> <p class="hint">{xen:phrase you_will_receive_emails_sent_by_administrator_to_all_members}</p></li>
            </ul>
        </dd>
    </dl>

    <link rel="xenforo_template" type="text/html" href="account_privacy_dob.html" />
    
    </xen:hook>
 
Ah, ok. I Oversee that.


Another way is, to use jQuery.
untestet.

Code:
$('dl.ctrlUnit').first().remove();
 
Ah, ok. I Oversee that.


Another way is, to use jQuery.
untestet.

Code:
$('dl.ctrlUnit').first().remove();
again the problem that nobody can garantee that the element is places as the first because a add-on could place something before this...:(
And i had this in my first version with jquery searching for name="visible" and then using parent() several times until i was in the container, BUT it's IMO again a hackish solution because it works only with js....
 
There ar several other ways.

javaScript:
Code:
$('input#ctrl_visible').parent().parent().parent().parent().remove();

PHP:
Divide the $contens into an Array with the Top dl Tags with preg_split.
search the uinique id (id="ctrl_visible") and unset the Array Element.
Rebuild $contents
 
It's not possible to search for the phrase on template_post_render because the template is already rendered/parsed there:(


Edit: ok some hackish code did it

thx
What I said was for a parsed template... guessing you figured that out though.
 
Top Bottom