tofty VIP
Total posts: 54
19 Feb 2017 06:56

Hello,

I have some articles that are to be viewable only when people are logged in as a registered user.

The Section listing and Category listing show these in the list to everyone, to the Public. That is fine.

But I'd like the Read More button to be different for those articles that are only for Registered and logged in users. For example, in the regular Joomla articles, when someone is not logged in, it shows the text "Register to Read More..." instead of Read More and then when you click it, it takes the user to the Login screen.

I would like to be able to do the same thing within my Cobalt articles (which is where all my articles are - I don't use regular Joomla articles).

How can I do that?

Thora

Last Modified: 19 May 2017


pepperstreet VIP
Total posts: 3,837
20 Feb 2017 01:18

Hello Thora, How do you use and insert the "ReadMore"? Within an HTML field?

What about the build-in Intro/Full view feature? You might use some data and fields on list, and other fields on full record view.

Do you have "mixed" content in your section? I mean, some articles have public access, and others have "registered"?


tofty VIP
Total posts: 54
20 Feb 2017 05:51

Hi Pepperstreet,

The Read More is just part of the template I chose when setting up the Types and Fields. Yes, it is an html field. I used the deafault Read More text for the field, which has a checkbox to ask if the Read More button is included; it is in the Intro Text section of the field.

I actually do use a different field for display on the List view. That particular field won't show in the Full Article view.

I do have mixed content in this section. I have articles that I want everyone to see the summary of, but then some will require them to be a member to view the full article. Thus if I can have different text on the Read More button, they'll know they need to sign up to see them, and I can link it to the Sign Up page.

If you want to see what I have, this is the page:

https://feast-for-freedom.com/cook/recipes

The recipe "Ranch Dressing" is the one at the moment that is set to be Registered Users only.

Thora


Sergey
Total posts: 13,748
21 Feb 2017 04:42

You can use in template something like this.

<?php if(in_array($item->access, JFactory::getUser()->getAuthorisedViewLevels())): ?>
    read more
<?php else: ?>
    no access
<?php endif; ?>

tofty VIP
Total posts: 54
21 Feb 2017 06:21

Hi Sergey,

Thanks. At this point, that is way above my skill level to implement.

I think I'll just create a field and insert a Read More button, and I'll have multi versions. Or somehow come up with a solution of some sort. I'll start another post if I need help creating it.

Thora


pepperstreet VIP
Total posts: 3,837
22 Feb 2017 04:23

tofty Thanks. At this point, that is way above my skill level to implement.

I think I can help you out with the field output template… but not before weekend.

Which list template are you using right now? Maybe you can attach a .ZIP here.


tofty VIP
Total posts: 54
22 Feb 2017 06:18

Hi Pepperstreet,

That would be awesome! I'm not in a hurry, so whenever you have time, would be great!

I've attached a zip of the .php and .xml of the template - the default_list_table

Let me know if you need any more info.

Thora-Cobalt-Template

Thank you.

Thora


pepperstreet VIP
Total posts: 3,837
28 Feb 2017 03:24

Hello Thora, my first assumption with the field output template is wrong, at least not very clean. Apparently all "readmore" related output happens in the field's main PHP file. Before the complete value is "echo'ed" in the end.

Sergey's hint is more applicable. The Adv.table template should output the custom readmore/button. The condition is quite right for the general display. But I think there are some other things to consider:

You have a link on the image and the title, too. I guess you want to keep those links for:

  • all public records
  • registered records (logged in users)

Otherwise, guest users would still run into the "no access error message". People are lazy and tend to click the title/image instead of the readmore button ;)


The Adv.table template has parameters to display the link for a certain ACL/group. But that does not help for your "mixed" content, right? Link on title/image should be removed for guest users depending on record status "registered". What do you think?


tofty VIP
Total posts: 54
11 Mar 2017 05:05

Hi Pepperstreet,

Sorry I haven't responded. I have been swamped with other things for a while.

For the links / recipes, that are for members only, when people are not logged in, they get a page that shows the error warning "Error - You have no rights to view this page".

Is there some way to customize this error message? If so, then maybe I could change the text to direct them to get the Free download, which also includes the free membership - and this is always in the sidebar, so it would be right there for them to see.

Or, is there some way to "redirect" when people click a link / article that they don't have permission for? If so, I can direct them to a page I have to "sign up".

Thora


tofty VIP
Total posts: 54
19 Mar 2017 04:59

Hi,

I have found a work around, since I don't know php.

1 - First, I turned off displaying the Read More button on the intro text. 2 - I created 2 fields. Each display a different Read More (via html code). One is Read More, and one is "Register to Read More". I have one field to show the regular link when people are signed in as Registered, and customized it to only show for them (via access permissions). The other one is for "Guests". It doesn't show when people are signed in. For this field, I can change the html code in it, based on if this is a public article or a Registered only article. If it's a Registered only article, then I just send them to my login page. For the public article, I can paste in the article url.

Now, to make things easier, I'd like to be able to just grab the page url of the article this field is in, and use that inside my html code. But I don't know how to format it. I did see the article that explained the php code to use, but I don't know how to use it in my html field. This is the code from the article:

<?php echo JRoute::_($item->url);?>

This is the html code I'm using:

<a href="#" class="btn btn-primary btn-small">Read More...</a>

where the # would be the url of the page. How can I combine the php code that will pull the url, and the html code, to use in an html field? Note this is not used in a template, but directly in an html field.


UPDATED April 4 On a related topic for this task, is there a way to redirect people when they click on an article that they don't have permission for? Right now, people just get an error page. I have found where to change the copy of this error, so I can change that, but it would be even better if I could simply redirect them to the login page. UPDATED April 4 - I solved this lower item by customizing the button link, so they manually trigger a popup that offers them a free membership; and customized the error message they see when they click the title, so the error messages has text and a link to direct them go get a free membership.

Thank you.

Thora


pepperstreet VIP
Total posts: 3,837
20 Mar 2017 12:24

Hello tofty, sorry for the silence. I am very busy and short on free time.

Clever idea… to solve it by configuration. But I would not recommend multiple fields.
Also PHP won't run inside your HTML field. For obvious security reasons. All this logic should go into templates.

Stay tuned, I try to post a possible solution until the end of the week.


pepperstreet VIP
Total posts: 3,837
05 Apr 2017 23:52

Sorry for the silence, I am pretty busy and free time is rare.

tofty UPDATED April 4 On a related topic for this task, is there a way to redirect people when they click on an article that they don't have permission for? Right now, people just get an error page. I have found where to change the copy of this error, so I can change that, but it would be even better if I could simply redirect them to the login page. UPDATED April 4 - I solved this lower item by customizing the button link, so they manually trigger a popup that offers them a free membership; and customized the error message they see when they click the title, so the error messages has text and a link to direct them go get a free membership.

Thank you.

Thank YOU for your feedback! Glad you have found a solution.

PS: Although I still think it is better to prevent the user of an "error message". Maybe it is more userfriendly to give "visual feedback" what is free and clickable... and what not.


Sergey
Total posts: 13,748
10 Apr 2017 12:04

I am not sure Paperstret can see your private topics. He is not and admin and hi is not an author.


pepperstreet VIP
Total posts: 3,837
10 Apr 2017 16:02

Sergey I am not sure Paperstret can see your private topics. He is not and admin and hi is not an author.

I can't see any private comments in this topic... are there any?


tofty VIP
Total posts: 54
11 Apr 2017 06:18

Hi Pepperstreet and Sergey,

I'm sorry, I assumed you could see my message. Sergey, you are welcome to provide my email address to Pepperstreet, if he wants it, or let me know how best to provide that to you if you want it. Here it is open:


No problem on the silence. I understand you are busy.

I wanted to ask if you, or someone you know, does private paid work for just this kind of issue I'm having.

If so, let me know your rates, and anything else I might need to know. I may be intereseted in having this custom coded properly in a template.

Thank you.

Thora


Sergey
Total posts: 13,748
13 Apr 2017 06:40

I know few people but unfortunately they do not speak english.

Leave your email here and paperstreet will send you a message if he can help you.


tofty VIP
Total posts: 54
15 Apr 2017 20:14

Hi Pepperstreet,

Here is my email if you are interested:

thora at feast-for-freedom dot com

Thank you.

Thora


tofty VIP
Total posts: 54
18 May 2017 03:06

Hi Pepperstreet,

Thank you. I've now responded to your email. I really appreciate it. :)

Thora

Powered by Cobalt