Jump to content

Recommended Posts

Posted

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.

Posted

That's not the issue ? but thanks for spotting it.

The example I posted had a typo but the actual code used was correct.

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

 

Posted

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
Posted

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
Posted

Thanks you both. It's working somewhat inexplicably now with no changes at my end ?

I have a feeling a database and server backup which was running was affecting this. That's the only explanation I can think of.

 

  • Like 2

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
×
×
  • Create New...