Warning: This page has not been updated in over over a year and may be outdated or deprecated.
development:howtos:displaying_a_custom_field
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
development:howtos:displaying_a_custom_field [2020/04/14 12:05] – [Understanding VuFind Displays] demiankatz | development:howtos:displaying_a_custom_field [2020/04/14 12:42] – [4. Step-by-step examples] demiankatz | ||
---|---|---|---|
Line 52: | Line 52: | ||
As with code customizations, | As with code customizations, | ||
- | ===== 4. Step-by-step | + | ===== 4. Step-by-step examples ===== |
- | + | ||
- | // This example shows you how to set up a custom module, custom theme and custom record driver. It assumes that you have already added a custom field to your Solr index named RecID -- you can see more concrete | + | |
- | + | ||
- | 1. Create a custom module (if you haven' | + | |
- | cd $VUFIND_HOME | + | |
- | php install.php | + | |
- | + | ||
- | * At the prompt "What module name would you like to use? [blank for none]" type in your module name | + | |
- | * Link configuration to apache’s config.d directory per the install.php directions | + | |
- | * Restart apache (sudo / | + | |
- | + | ||
- | 2. From $VUFIND_HOME enter the following code generator command: | + | |
- | php public/ | + | |
- | + | ||
- | * You should see the following: | + | |
- | + | ||
- | Saved file: / | + | |
- | Saved file: / | + | |
- | | + | |
- | + | ||
- | * If you get an error like "Class ModuleName\RecordDriver\Factory does not exist", | + | |
- | + | ||
- | | + | |
- | php public/ | + | |
- | + | ||
- | 3. Update the SolrMarc.php file to add a new field. | + | |
- | * Make sure the namespace line reads “namespace ModuleName\RecordDriver; | + | |
- | * Add the getter method. See below for an example, but also reference the SolrMarc.php file in / | + | |
- | + | ||
- | | + | |
- | <? | + | |
- | | + | |
- | class SolrMarc extends \VuFind\RecordDriver\SolrMarc | + | |
- | { | + | |
- | /** | + | |
- | * Get the record ID of the current record. | + | |
- | * | + | |
- | * @return string | + | |
- | */ | + | |
- | public function getRecordID() { | + | |
- | return isset($this-> | + | |
- | | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | 4. Customize the template where you want to use that field by copying the appropriate files into your custom theme. | + | |
- | cd $VUFIND_HOME/ | + | |
- | mkdir ThemeName | + | |
- | + | ||
- | * Make the following sub-directory structure: ThemeName/ | + | |
- | * Put the following content in $VUFIND_HOME/ | + | |
- | + | ||
- | < | + | |
- | <?php | + | |
- | return array( | + | |
- | ' | + | |
- | ); | + | |
- | </ | + | |
- | + | ||
- | * cd $VUFIND_HOME/ | + | |
- | * Edit core.phtml and result-list.phtml to add new fields for display. | + | |
- | + | ||
- | Example: | + | |
- | <? $recordID | + | |
- | < | + | |
- | < | + | |
- | < | + | |
- | </ | + | |
- | <? endif; ?> | + | |
- | + | ||
- | :!: Note that, starting with VuFind 4.0, the [[development: | + | |
- | + | ||
- | * Edit local/ | + | |
+ | * [[development: | ||
+ | * [[development: | ||
---- struct data ---- | ---- struct data ---- | ||
---- | ---- | ||
development/howtos/displaying_a_custom_field.txt · Last modified: 2020/09/22 13:27 by demiankatz