Tisch
Tisch

Reputation: 2647

How Do I Add a Class to a CodeIgniter Anchor

I have the following:

'.anchor('','Home').'

and I want to add the following CSS class to it:

class="top_parent"

This is so that when it's rendered in the browser, the code will look something like the following:

<a href="#" class="top_parent">Home</a>

Thanks in advance, and any help is greatly appreciated.

--

Tom

Upvotes: 12

Views: 25459

Answers (7)

Zamir
Zamir

Reputation: 441

From Codeigniter's manual:

anchor() has three optional parameters:

anchor(uri segments, text, attributes)

Simple example:

anchor(url,text,array('class'=>'class1'));

Upvotes: 0

kaysums
kaysums

Reputation: 1

For example if you have a css class called btn, and a button called submit, to submit (call a submit controller class called sub) You can do it this way

<?php echo anchor('sub', 'submit', 'class="btn" ');? >

Upvotes: -2

Try this:

$myClass = array('class' => 'top_parent');

echo anchor('#', 'Home', $myClass);

Hope it will be clear to you.

Upvotes: 1

Joe
Joe

Reputation: 1

It can also be used like this:

<?php echo anchor('#', 'Home', 'class="top_parent"' ); ?>

And if you want extra attributes like title for example, it can be done like this:

<?php echo anchor('#', 'Home', 'class="top_parent" title="Home"' ); ?>

Upvotes: 0

Whitey
Whitey

Reputation: 73

You can specify an associative array of attributes for your Anchor. So, for example:

anchor('', 'Home', array('class' => 'top_parent'));

Upvotes: 3

IEnumerator
IEnumerator

Reputation: 2972

The Codeignitor function is defined as such:

function anchor($uri = '', $title = '', $attributes = '')

I would try sending an array with a class key and value first.

These functions are found inside the \system\helpers\ folder.

Upvotes: 5

Mahtar
Mahtar

Reputation: 1941

anchor('#', 'Home', array('class' => 'top_parent'));

Upvotes: 26

Related Questions