How to suppress Joomla output

This forum is for general questions about extensions for Joomla! 3.x.

Moderators: pe7er, General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Locked
Jim Holloman
Joomla! Intern
Joomla! Intern
Posts: 65
Joined: Thu Apr 25, 2013 4:05 am

How to suppress Joomla output

Post by Jim Holloman » Mon Mar 29, 2021 8:06 pm

Can someone tell me the basic PHP Code that is needed to suppress Joomla output for portions of an article -- and also the event that it would be attached to -- like perhaps onContentPrepare?

For example, I would like to have a Plugin that would hide code as follows:

{hide}This content is not rendered.{/hide}

{show}This content is rendered{/show}

--------

Much better would be the use of an embedded flag, or switch, that would be embedded at the beginning of an article.

<!-- paid --> // First line of the article -- it could also be <!-- nonpaid -->
Then,
{show if paid} This content is rendered. {/show] // If 'paid' is defined in a HTML Comment
{hide if !paid} This content is not rendered. {/hide} // If 'paid' is not defined

Naturally, this approach would require some sort of search for the keyword 'paid'.

'Content' can be any valid HTML.

For this functionality, I am currently using CSS 'display: none;'. That is not efficient because the hidden code is still transferred to the client. In addition, it may cause Google to see duplicate data.

User avatar
john-doe
Joomla! Ace
Joomla! Ace
Posts: 1008
Joined: Tue Apr 19, 2011 7:39 pm
Location: Colombia
Contact:

Re: How to suppress Joomla output

Post by john-doe » Mon Mar 29, 2021 8:20 pm

Are you looking for some kind of Paywall?
www.aldemar-hernandez.com - Custom templates and design services.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30890
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: How to suppress Joomla output

Post by Per Yngve Berg » Mon Mar 29, 2021 8:21 pm


Jim Holloman
Joomla! Intern
Joomla! Intern
Posts: 65
Joined: Thu Apr 25, 2013 4:05 am

Re: How to suppress Joomla output

Post by Jim Holloman » Mon Mar 29, 2021 11:43 pm

Thanks, Per Yngve Berg

I was able to create a Plugin. It is the functional code that I do not know how to add.

The sample on the "Creating a Content Plugin" from the link you provided gives:

// Find all instances of plugin and put in $matches for loadposition
// $matches[0] is full pattern match, $matches[1] is the position
preg_match_all($regex, $article->text, $matches, PREG_SET_ORDER);

For my purpose, I need code that tells Joomla to temporarily Stop rendering output.

Jim Holloman
Joomla! Intern
Joomla! Intern
Posts: 65
Joined: Thu Apr 25, 2013 4:05 am

Re: How to suppress Joomla output

Post by Jim Holloman » Tue Mar 30, 2021 12:07 am

john-doe wrote:
Mon Mar 29, 2021 8:20 pm
Are you looking for some kind of Paywall?
Thanks, John Doe.

Paywall: https://en.wikipedia.org/wiki/Paywall

Sort of, but more granular.

An article can have content that renders ONLY if paid -- intermingled with content that always renders.

With CSS: .hide { display: none; }

<div class="Xhide">This shows</div>
<div class="hide">This DOES NOT show</div>
<div class="Xhide">This shows</div>
<div class="hide">This DOES NOT show</div>
<div class="Xhide">This shows</div>
<div class="hide">This DOES NOT show</div>
<div class="Xhide">This shows</div>
<div class="hide">This DOES NOT show</div>

By switching Xhide to hide -- and hide to Xhide -- I can do a flip-flop. I use an external program to do so; updating only Field 5 (introText) of the "_content" table. But, all the content is still sent to the client; even if half of it is not seen by the user.

With a plugin:
{show}<div>This shows</div>{/show}
{hide}<div>This DOES NOT show</div>{/hide}
{show}<div>This shows</div>{/show}
{hide}<div>This DOES NOT show</div>{/hide}
{show}<div>This shows</div>{/show}
{hide}<div>This DOES NOT show</div>{/hide}
{show}<div>This shows</div>{/show}
{hide}<div>This DOES NOT show</div>{/hide}

Now, only what is to be seen is sent to the client; none of the content wrapped in {hide}{/hide} is sent.

The extensions that I have found are way overkill for my simple requirement. All I need is a small, light-weight Plugin. It need support only English. It needs no integration with any content editor. A simple condition based upon 'paid' or 'nonpaid' in a HTML Comment at the beginning of the article would be very useful -- but not essential. Then, only one place to change.

I have created a Plugin. But, what is the PHP that would tell Joomla not to render the content wrapped in {hide}{/hide}. I have no idea.

I searched for Paywall
https://extensions.joomla.org/instant-s ... 5D=Paywall
and found only 2 extensions -- neither of them suitable.
Last edited by Jim Holloman on Tue Mar 30, 2021 12:31 am, edited 1 time in total.

Jim Holloman
Joomla! Intern
Joomla! Intern
Posts: 65
Joined: Thu Apr 25, 2013 4:05 am

Re: How to suppress Joomla output

Post by Jim Holloman » Tue Mar 30, 2021 12:28 am

Perhaps my thinking is on the wrong track.

Perhaps I just need to strip out the Content between {hide}{/hide] as well as any {show]{/show} shortcodes instead of trying to tell Joomla to stop and start rendering.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 30890
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: How to suppress Joomla output

Post by Per Yngve Berg » Tue Mar 30, 2021 3:49 am

Jim Holloman wrote:
Tue Mar 30, 2021 12:28 am
Perhaps I just need to strip out the Content between {hide}{/hide] as well as any {show]{/show} shortcodes instead of trying to tell Joomla to stop and start rendering.
Exactly.

You can replacement with a link to subscription.


Locked

Return to “Extensions for Joomla! 3.x”