I want to get access to a special field value, do some processing or manipulating on it and then place it back in theme. For example, I've created a custom content type that name is "News" and has a field with below properties:
- label: News Number
- machine name: news_num
- value: Number (float)
I did content-type node theming with name node--news.html.twig, Now I want to understand Is there any preproccessing hook to modify or altering the field value and in addition I want to learn right way for manipulate the field value, I wrote something like below code:
ThemeName.theme:
function ThemeName_preprocess_node(&$variables) {
// Get access to field value:
$value = $variables['node']->news_num();
/**
* Makeing some manipulation on $value here.
*/
$variables['value'] = $value;
}
- The type of operation is not really important; I'm most looking for a solution to learn standard method and general format to access and modify the field value.
- I just want to overview the field value (alter the field value before rendering) and not doing any override or change the field value in the database.
Any suggestions?