• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Remove content inside of template hook

R

ragtek

Guest
#1
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 :(
 

Robbo

Well-known member
#2
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.
 
R

ragtek

Guest
#3
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... :(
 

Robbo

Well-known member
#4
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.
 
R

ragtek

Guest
#5
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
 

digitalpoint

Well-known member
#6
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.
 
R

ragtek

Guest
#9
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>
 
R

ragtek

Guest
#11
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....
 

Hoffi

Well-known member
#12
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
 

Robbo

Well-known member
#13
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.