Forum

Thread tagged as: Question, Problem, Suggestions

Internal links in rich text editor

Is there a way to link to internal pages from one of the rich text editors? I would like to be able to select a page from within perch instead of inserting an external link. This would help with updating those links when changing the url of a linked page.

Cheers, Daniel

Daniel Blomeyer

Daniel Blomeyer 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Which of the editors are you using?

I have been using Markitup and Redactor.

Drew McLellan

Drew McLellan 2638 points
Perch Support

And the requirement is that the link is essentially a reference, so that it's resolved to the current page location at runtime?

Yeah I will try to explain it with a little example.

e.g. I have a page at "/about.php" and want to link to that page from a rich text field on another page. I would have to insert a link and type in "/about.php" or a complete url like "https://site.tld/about.php"

Instead of that I would like the user to be able to select the about page that is managed by perch and insert the url automatically. And after all it would be nice to keep a reference to that page so that if the url changes I don't have to update that link with the new url. That would mean that perch would have to resolve the current location at runtime (like for navigation?)

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, great. I've got an idea about a new feature we're working on and how it might help with this. I'll take these suggestions into consideration with how it's designed.

Nice, sounds good. It might also be nice to have the same functionality as a field type. Maybe you can take that into consideration, too.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you tried the pagelinks field type?

I guess you mean the pagelist field type? No I actually overlooked that by only searching through the documentation leaving out the “Add-ons & Plugins” section on the homepage. Thank you for the hint. That works.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, sorry, autocorrect got me on that twice.

+1 for giving users the ability to choose a page link from within editor (markitup/redactor).

Simon Clay

Simon Clay 127 points

+1 from me too, again, markitup and Redactor.

I have a very simple plugin for Redactor, if you want I can share it.

Sounds interesting. Can you post a link? Thanks!

Dropbox link.

I believe the script that generates the links could be use with any editor. In the link provided, only the redactor(latest version) plugin is included, but I made as a separate plugin so it could be used with the others.

Making a dialog for markitup requires a little more work.

Just been trying out Andrés Fernández redactor plugin for adding links. Works great!

Simon Clay

Simon Clay 127 points

Andrés, Great work! Thank you for sharing.

I made a tiny adjustment to padding and added a label to the select list by adding this to my custom UI CSS:

#redactor-modal-link-insert section {
    padding: 0;
}

#redactor-modal-link-insert section:before {
    content: "Page";
}

Thanks again.

Andrés Fernández thank you for the solution. This is close but is still missing out on keeping a reference to the selected page after saving. It works for now but I am still looking forward to an official solution that might be implemented by Drew in the future.

Simon Clay

Simon Clay 127 points

I'm not sure it will come anytime soon. I don't think it's high on the importance list.

Until your excellent solution, to create a link to internal pages, I've had to tell editors to navigate to the page in their site they want to link to, copy the URL, come back into Perch, create the link, paste in the url minus the www.theirsite.com part.

So, I'm very grateful for your work.

I find it surprising that this isn't a niggling problem for more users and that the feature hasn't at least made it into Markitup.

I understand the Rachel and Drew don't want to spend their time updating Redactor and the other editors constantly though.

Simon, the syle issues can be solved by replacing the select container element(line 11 in redactorlinks.js), you can also add a label. The code should look like this:

            load: function() {
                var $section = $('<div />');
                var $label = $('<label>Pages</label>');
                var $select = $('<select id="redactor-perch-links" />');

                $section.append($label);
                $section.append($select);

Daniel, the plugin was posted as a very simple solution you can use as a starting point for a bespoke plugin. For example, the regions we use with redactor I have a multiple region(not a repeater) template that requires a title(rendered as an h2) and add an anchor link, which I include in the 'perchlinks' plugin dropdown so the editor can also add link to those regions.

+1 for the feature