Modifying Templates

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
Post Reply
rpierce
Veteran Member
Posts: 308
Joined: 2018-11-26 13:55
Location: Washington State

Modifying Templates

Post by rpierce » 2025-09-08 18:18

Hi AppGeniuses,

I want to add the week number of the year in big bold red letters to a page in my App. I see in the template file that it says: To change the layout of the detail view form, we recommend using JS code in hooks/table-name-dv.js rather than editing this file.

I don't know how to edit the file and have used code found in this forum to do other modifications. I found the code below but have no idea of how to implement in in AppGini. If anyone has help to offer I'd be grateful. I simplw want to add the text: We are currently in week # 37 (or whichever week it is) for 2025 (Current Year).

Is this code any good? If so, how do I use in in table-name-dv.js??

Code: Select all

function getDateWeek(date) {
    const currentDate = 
        (typeof date === 'object') ? date : new Date();
    const januaryFirst = 
        new Date(currentDate.getFullYear(), 0, 1);
    const daysToNextMonday = 
        (januaryFirst.getDay() === 1) ? 0 : 
        (7 - januaryFirst.getDay()) % 7;
    const nextMonday = 
        new Date(currentDate.getFullYear(), 0, 
        januaryFirst.getDate() + daysToNextMonday);

    return (currentDate < nextMonday) ? 52 : 
    (currentDate > nextMonday ? Math.ceil(
    (currentDate - nextMonday) / (24 * 3600 * 1000) / 7) : 1);
}

const currentDate = new Date();
const weekNumber = getDateWeek();

console.log("Week number of " + currentDate + " is : " + weekNumber);
Thank you,
Ray

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1710
Joined: 2018-04-01 10:12

Re: Modifying Templates

Post by pbottcher » 2025-09-08 18:47

Hi Ray,

you may try to do something like the following:

go to the tablename.php in the hooks folder and go the _header function. Here you can add to the detailview something like:

Code: Select all

			case 'detailview':
				$calenderweek=date("W");
				$header='<%%HEADER%%><script>$j(function(){
					$j(".page-header h1 a").after("<div>'.$calenderweek.'</div>")
					})</script>';
				break;
This would add the calenderweek after the header. If you want to place it somewhere else, you need to modify the placement in $j(".page-header h1 a")
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

rpierce
Veteran Member
Posts: 308
Joined: 2018-11-26 13:55
Location: Washington State

Re: Modifying Templates

Post by rpierce » 2025-09-11 16:26

Pascal,

THANK YOU!! It works. :)

rpierce
Veteran Member
Posts: 308
Joined: 2018-11-26 13:55
Location: Washington State

Re: Modifying Templates

Post by rpierce » 2025-09-11 16:37

One question, can I make the text Red?

saymaad
AppGini Super Hero
AppGini Super Hero
Posts: 61
Joined: 2024-06-03 16:17

Re: Modifying Templates

Post by saymaad » 2025-09-12 14:34

To make the div containing the calendar week display as red bold text, you can simply apply inline CSS styles directly to the div element:

Code: Select all

case 'detailview':
	$calenderweek = date("W");
	$header = '<%%HEADER%%><script>
		$j(function(){
			$j(".page-header h1 a").after("<div style=\'color: red; font-weight: bold;\'>" + "'.$calenderweek.'" + "</div>");
		});
	</script>';
	break;


Post Reply