Development BlogStyle selector for Attachment Shields

Post Reply
User avatar
Topic Starter
Restless Rancor
Great Britain

Site Admin
New Member
Posts: 48
Joined: October 15th, 2018, 3:14 pm
Age: 25
Location: Hampshire, England
Contact:

Style selector for Attachment Shields

#1

Post by Restless Rancor » October 29th, 2018, 4:04 pm

I tasked myself with adding a Style selector for the Attachment Shields extension today and have been succesfull.

I'm not 100% about how it's handled and am sure it can improve, but what I've done is add a standard options drop-down in adm/style/acp_ashields_body.html:

Code: Select all

<select name="ashields_style">
	<option value="0"<!-- IF ASHIELDS_STYLE == "?LongCache=true&style=flat" --> selected="selected"<!-- ENDIF -->>{{ lang('ASHIELDS_FLAT') }}</option>
	<option value="1"<!-- IF ASHIELDS_STYLE == "?LongCache=true&style=plastic" --> selected="selected"<!-- ENDIF -->>{{ lang('ASHIELDS_PLASTIC') }}</option>
	<option value="2"<!-- IF ASHIELDS_STYLE == "?LongCache=true&style=flat-square" --> selected="selected"<!-- ENDIF -->>{{ lang('ASHIELDS_FLAT_SQUARE') }}</option>
	<option value="3"<!-- IF ASHIELDS_STYLE == "?LongCache=true&style=for-the-badge" --> selected="selected"<!-- ENDIF -->>{{ lang('ASHIELDS_FOR_THE_BADGE') }}</option>
	<option value="4"<!-- IF ASHIELDS_STYLE == "?LongCache=true&style=popout" --> selected="selected"<!-- ENDIF -->>{{ lang('ASHIELDS_POPOUT') }}</option>
	<option value="5"<!-- IF ASHIELDS_STYLE == "?LongCache=true&style=popout-square" --> selected="selected"<!-- ENDIF -->>{{ lang('ASHIELDS_POPOUT_SQUARE') }}</option>
	<option value="6"<!-- IF ASHIELDS_STYLE == "?LongCache=true&style=social" --> selected="selected"<!-- ENDIF -->>{{ lang('ASHIELDS_SOCIAL') }}</option>
</select>
And in the listener, assign the config value the style, based on the form value:

Code: Select all

// Assign each style value to the template
if ($this->config['ashields_style'] == 0)
{
	$this->template->assign_vars(array(
	'ASHIELDS_STYLE'	=> '?LongCache=true&style=flat',
	));
}
if ($this->config['ashields_style'] == 1)
{
	$this->template->assign_vars(array(
	'ASHIELDS_STYLE'	=> '?LongCache=true&style=plastic',
	));
}		
if ($this->config['ashields_style'] == 2)
{
	$this->template->assign_vars(array(
	'ASHIELDS_STYLE'	=> '?LongCache=true&style=flat-square',
	));
}		
if ($this->config['ashields_style'] == 3)
{
	$this->template->assign_vars(array(
	'ASHIELDS_STYLE'	=> '?LongCache=true&style=for-the-badge',
	));
}		
if ($this->config['ashields_style'] == 4)
{
	$this->template->assign_vars(array(
	'ASHIELDS_STYLE'	=> '?LongCache=true&style=popout',
	));
}		
if ($this->config['ashields_style'] == 5)
{
	$this->template->assign_vars(array(
	'ASHIELDS_STYLE'	=> '?LongCache=true&style=popout-square',
	));
}		
if ($this->config['ashields_style'] == 6)
{
	$this->template->assign_vars(array(
	'ASHIELDS_STYLE'	=> '?LongCache=true&style=social',
	));
}
I'm sure it can be optimized into a much simpler process, but this enables me to use {{ ASHIELDS_STYLE }} in template files to call the configured style and therefore the following can be used:

Code: Select all

<img src="https://img.shields.io/badge/filesize-{{ _file.FILESIZE }} {{ _file.SIZE_LANG }}-{{ S_ASHIELDS_COLOR }}.svg{{ ASHIELDS_STYLE }}">
I need to decide if I'm adding more variety to the customization of this extension (I probably will) and act on that decision before running optimizations, but I'm happy with how this extension is progressing.


These aren't the droids you're looking for.

Post Reply

Topic Subscribers

1 user subscribed to this topic: Restless Rancor