在HTML中访问php数组元素

时间:2019-02-25 12:27:28

标签: php html5

我在php中有这个

'position' => [
			'label' => ['Pic Position', ''],
			'inputType' => 'select',
			#'default' => 'left',
			'options' => [
				'left' => 'Left',
				'right' => 'Right',
			],
		]

现在我想如果选择“ Left”,则将一个名为left的类添加到div中!我无法弄清楚它的php语法!

<div class="floating_text" <?php if ($this->position == 'left') echo 'class="left"' ?>>
		<?= $this->text ?>
	</div>

这显然是错误的!

2 个答案:

答案 0 :(得分:1)

将您的PHP条件移动到现有的import { Component, OnInit } from '@angular/core'; import { AuthService } from 'src/app/auth/auth.service'; import { Router } from '@angular/router'; import * as firebase from 'firebase/app'; @Component({ selector: 'app-navbar', templateUrl: './navbar.component.html', styleUrls: ['./navbar.component.scss'] }) export class NavbarComponent implements OnInit { user: any; constructor( private authService: AuthService, private router: Router) {} ngOnInit() { this.authService.getAuthState().subscribe( user => { /* this doesn't respond to logout ... */ console.log(user); this.user = user; }); } tryLogout() { this.authService.doLogout() .then(res => { console.log('tryLogout', res); this.router.navigate(['/login']); }, err => console.log(err)); } } 中,而不是尝试创建另一个错误的class=实例。

class=

答案 1 :(得分:0)

@kerbholz感谢您的提示!

internalMethod

或者我也可以这样做:

<div class="floating_text <?php if ($this->position === 'left') echo left ?>">