Jump to content

Can't link to external URL


Peter Knight
 Share

Recommended Posts

Is I have a field called 'external_link' which accepts a url, is there an issue with the following code?

<a href="http://www.<?=$page->external_link?>">Visit site</a>

I've tried making the fieldtype both URL and Text and nothing seems to work and I send up with the following code when viewing source.

<a href="http://www">Visit site</a>

Normally I'd suspect that I named the field incorrcetly in my PHP or that the field isn't associated with the correct template etc. In this case, thats not the issue.

Link to comment
Share on other sites

Ok, something is with your "$page->external_link", this quick test works fine here:

<?php
$page = new stdClass();
$page->external_link = 'processwire.com';
?>
<a href="http://www.<?=$page->external_link?>">Visit site</a>

Perhaps $page is not the page you would like to use?

What type of field is "external_link"?

  • Like 1
Link to comment
Share on other sites

Not related to your problem, but I wouldn't recommend inserting "http://www." like that for a few reasons:

1) A site editor could easily add that part themselves - especially if they copy from their browser address bar and then you would have it twice

2) The site may not work with with the www subdomain - unlikely, but possible

3) They might want to link to a different subdomain rather than the www one

4) The site might be https, not http - most likely it would redirect automatically, but it just feels wrong to try to force this

  • Like 2
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...